Understanding MySQL-Proxy Setup
By Will Mayall
Discoverorg
03-July-214
Contents
Getting Started with the mysql-proxy.conf file ........................................................ 1
Starting, Stopping, and Restart mysql-proxy................................................................ 2
Verify mysql-proxy is Running ................................................................................................. 2
Check the Active Ports .................................................................................................................. 3
4041 – The LUA ADMIN PORT ....................................................................................................... 3
3306 – The MySQL PORT ................................................................................................................ 5
3307 – The MySQL-PROXY PORT .................................................................................................. 6
Summary ...................................................................................................................................................... 7
Getting Started with the mysql-proxy.conf file
Below is the mysql-proxy.conf files.
NOTE:
The admin-username and admin-password can be whatever
you make them, they are not tied directly to MySQL or
the Operating System. The rest of the parameters seem
pretty obvious on their intent.
root@db40:~# cat /etc/enterprise_mysql/mysql-proxy.conf
[mysql-proxy]
admin-username=frank
admin-password=frank1
admin-lua-script=/etc/enterprise_mysql/admin.lua
pid-file=/run/mysql-proxy.pid
proxy-backend-addresses=172.20.19.168:3306,127.0.0.1:3307
#proxy-read-only-backend-addresses=127.0.0.1:3307
1
proxy-address=0.0.0.0:3306
#proxy-lua-script=/etc/enterprise_mysql/routing.lua
proxy-lua-script=/etc/enterprise_mysql/report.lua
log-level=debug
log-file=/tmp/proxy.log
#log-use-syslog=true
proxy-skip-profiling=true
plugins=admin
root@db40:~#
Starting, Stopping, and Restarting mysql-proxy
The following commands can be used to start, stop, and
restart the mysql-proxy.
#service mysql.proxy start
#service mysql.proxy stop
#service mysql.proxy restart
Verify mysql-proxy is Running
Use the ps command to verify the mysql-proxy is
running:
root@db40:~# ps -ef |grep mysql-proxy
root
9310
1 0 Jul02 ?
00:00:14
/opt/mysql/proxy/libexec/mysql-proxy --defaultsfile=/etc/enterprise_mysql/mysql-proxy.conf
root
32494 32132
mysql-proxy
0 07:40 pts/4
00:00:00 grep --color=auto
root@db40:~#
2
Check the Active Ports
Using netstat –tulpn, note the following Ports:
4041 – The LUA ADMIN PORT
3306 – The MySQL PORT
3307 – The MySQL-PROXY PORT
wmayall@db40:~$ netstat -tulpn
(No info could be read for "-p": geteuid()=1005 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address
PID/Program name
Foreign Address
State
tcp
0
0 0.0.0.0:4041
0.0.0.0:*
LISTEN
-
tcp
0
0 0.0.0.0:3306
0.0.0.0:*
LISTEN
-
tcp
0
0 127.0.0.1:3307
0.0.0.0:*
LISTEN
-
tcp
0
0 0.0.0.0:22
0.0.0.0:*
LISTEN
-
udp
0
0 172.20.19.188:123
0.0.0.0:*
-
udp
0
0 66.135.48.100:123
0.0.0.0:*
-
udp
0
0 127.0.0.1:123
0.0.0.0:*
-
udp
0
0 0.0.0.0:123
0.0.0.0:*
-
udp6
0
0 ::1:123
:::*
-
udp6
0
0 fe80::225:90ff:fef1:123 :::*
-
udp6
0
0 fe80::225:90ff:fef1:123 :::*
-
udp6
0
0 :::123
-
:::*
wmayall@db40:~$
4041 – The LUA ADMIN PORT
To check the status of the mysql-proxy, connect using
the credentials in the /etc/enterprise_mysql/mysqlproxy.conf file.
3
Below I connect to the ADMIN PORT (4041) of the LUA
script for the HOST db40i:
wmayall@db40:~$ mysql -ufrank -p -P 4041 -h db40i
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.99-agent-admin
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Once connected you can check the status using the
following commands.
NOTE: The commands are case sensitive!
mysql> SHOW PROXY PROCESSLIST;
+------+----------------------+--------------------------+
| Id
| IP Address
| Time
|
+------+----------------------+--------------------------+
| 40
| 173.10.244.198:63866 | Thu Jul
3 00:16:41 2014 |
| 42
| 173.10.244.198:63867 | Thu Jul
3 00:16:42 2014 |
| 4
| 173.10.244.198:63843 | Thu Jul
3 00:15:11 2014 |
+------+----------------------+--------------------------+
3 rows in set (0.00 sec)
4
mysql> SELECT * FROM backends;
+-------------+--------------------+-------+------+
| backend_ndx | address
| state | type |
+-------------+--------------------+-------+------+
|
1 | 172.20.19.168:3306 | 2
| 1
|
|
2 | 127.0.0.1:3307
| 1
|
| 1
+-------------+--------------------+-------+------+
2 rows in set (0.00 sec)
mysql> show myerror;
ERROR 1105 (07000): my first error
mysql> show querycounter;
+---------------+
| query_counter |
+---------------+
|
51832 |
+---------------+
1 row in set (0.00 sec)
mysql>
3306 – The MySQL-PROXY PORT
Port 3306 is the Proxy MySQL Port.
database as follows:
You can access the
wmayall@db40:~$ mysql -uwam -P 3306 -h db40i -p
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 11083
Server version: 5.6.16-enterprise-commercial-advanced-log MySQL Enterprise Server Advanced Edition (Commercial)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
5
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show global variables like 'hostname';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| hostname
| db40
|
+---------------+-------+
1 row in set (0.00 sec)
mysql>
3307 – The MySQL PORT
The following command will access the standard MySQL
Port:
wmayall@db40:~$ mysql -uwam -P 3307 –p --socket=/tmpmysql/mysql.sock
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 11130
Server version: 5.6.16-enterprise-commercial-advanced-log MySQL Enterprise Server Advanced Edition (Commercial)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
6
mysql> show global variables like 'hostname';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| hostname
| db40
|
+---------------+-------+
1 row in set (0.00 sec)
mysql>
Summary
Setting up mysql-proxy was not as straightforward was
documented. We still need to add the LUA script for
Load Balancing, and Failover. Once we get everything
working, I’ll update this document.
7