MySQL��־����
��������־
������־
������־
һ���ѯ��־
�м���־
���ѯ��־
��������־
Ĭ�ϴ�������Ŀ¼
�����ʽ��mysql-bin.xxxxxx
�������ﵽ�����ļ����������,flush logs,����������
��������־��ʽ
�������
������
���
mysql-bin.index����������־�ļ������ļ�
�鿴��ǰ����ʹ�õĶ�������־�ļ�
mysql> SHOW MASTER STATUS;
�鿴���ڵĶ������ļ�
mysql> SHOW BINARY LOGS;
�鿴��������־�ļ�����
mysql> SHOW BINLOG EVENTS IN "file";
event:
timestamp
position,offset
event
MySQL���뼶��
READ-UNCOMMITED
READ-COMMITTED
REPEATABLE-READ
SERIALIZABLE
MySQL Replication-------MySQL����
Master��������Slave������
��Master�������ϲ�����д������صIJ���ʱ��Master���ڶ�������־�ļ��м�¼��Щ������ͬʱMaster����������־�ļ��е�����ͬ����Slave������һ�ݣ�Slave�������յ���Ϣʱ���ᱣ�浽�Լ��Ķ�������־�ļ��У��ٴӶ�������־�ļ��ж�ȡ������ݣ������Լ��е����
Master�������ϵ���־��Ϊ��������־
Slave�������ϵ���־��Ϊrelay log �м���־
MySQL֧��һ�����ģ��
�첽���ƣ�Master������������ɣ���������Ϊ�¼�д���������־���������ɹ�
��ͬ�����ƣ����ж�̨slave������ʱ��master�����Լ�����slave������ͬ����������־�ļ��������ɹ�
MySQL 5.5ǰ��֧�ְ�ͬ����5.5ʱ��google�з���ͬ��������֧��
MySQL�����Ӹ��Ƶ����ã�
����ʵ�ֱ���
�߿���
�������
scale out����̯����(Master����д����,Slave���������) rw-spliting ��д����
ͨ��MySQL����ʶ��MySQL�Ķ���д����
���Ӽܹ��У���ʹ��MySQL���?��������ĸ���д�������ӵĸ����������
˫��ģ�ͣ�������д����
��д���빤�ߣ�
mysql-proxy
amoeba
��ݲ�ֹ��ߣ�
cobar
MySQL����һ���Զ�ӣ���һ���ӷ�����ֻ������һ����������
MySQL 5.6��gtid,multi-thread replication
����MySQL���ƻ��裺
һ��master
1�����ö�������־
log-bin = master-bin
log-bin-index = master-bin.index
2��ѡ��һ��Ψһ��server id
server-id = { 1---2^32-1 }
3���������и���Ȩ���û�
REPLICATION SLAVE�� ���д�master��������־�и����¼���Ȩ��
REPLICAITON CLIENT����������master����ȡ�����Ϣ��Ȩ��
����slave
1�������м���־
relay-log =
relay-log-index =
2��ѡ��Ψһ��server-id
server-id = { 1 - 2^32-1 }
3����������������������ʼ�������
mysql>CHANGE MASTER TO MASTER_HOST='',MASTER_PORT='',MASTER_LOG_FILE='',MASTER_LOG_POS='',MASTER_USER='',MASTER_PASSWORD='' ;
mysql> START SLAVE;
�����̣߳�
master: dump thread
������slave���������ݶ�������־�ļ����¼�
slave:��IO_thread, SQL_thread
io_thread�����ڶ�ȡmaster���������ݵĶ�������־�ļ����¼�����������relay log
sql_thread�����ڴ�relay log�ж�ȡ�¼�����slave��������ִ��
mysql> START SLAVE; ������slave�������ϵ����������߳�
mysql> START SLAVE io_thread; ������io_thread�߳�
mysql> START SLAVE sql_thread�� ������sql_thread�߳�
MySQL�����Ӹ�������
�������� ��
172.16.1.1 server1.bj.com Master
172.16.1.2 server2.bj.com Slave
��� �� mysql-5.5.46-linux2.6-i686.tar.gz
1����master�ϰ�װMysql,���༭�������ļ�
��װmyql
# mkdir -p /mydata/data
# useradd mysql
# chown -R mysql.mysql /mydata/data/
# tar zxf mysql-5.5.46-linux2.6-i686.tar.gz -C /usr/local/
# cd /usr/local/
# ln -s mysql-5.5.46-linux2.6-i686/ mysql
# chown -R root.mysql /usr/local/mysql/*
# cp support-files/my-large.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
�༭�����ļ�
# vim /etc/my.cnf
log-bin=master-bin //���ö�������־�ļ�
log-bin-index=master-bin.index //���ö�������־�����ļ�
datadir=/mydata/data
binlog_format=mixed
server-id = 1 //ָ��������server-id��������ͬ
# /etc/init.d/mysqld start
Starting MySQL.... [ OK ]
��¼mysql������������ӵ�и���Ȩ���û�
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'172.16.1.2' IDENTIFIED BY 'replpass';
mysql> FLUSH PRIVILEGES;
2����slave�������ϰ�װmysql�����༭�������ļ�
# vim /etc/my.cnf
server-id = 11 //ָ��������server-id��������ͬ
datadir=/mydata/data
innodb_file_per_table=1
relay-log=relay-log //�����м���־�ļ�
relay-log-index=relay-log.index //�����м���־�����ļ�
# /etc/init.d/mysqld start
Starting MySQL... [ OK ]
��¼mysql������������master������
��¼mysql�������ϵ�mysql���鿴��ǰ����ʹ�õĶ�������־�ļ���ƣ������¼�λ��
master��
# mysql -u root
mysql> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000001 | 339 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> SHOW BINLOG EVENTS IN 'master-bin.000001';
+-------------------+-----+-------------+-----------+-------------+------------------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------+-----+-------------+-----------+-------------+------------------------------------------------------------------------------------+
| master-bin.000001 | 4 | Format_desc | 1 | 107 | Server ver: 5.5.46-log, Binlog ver: 4 |
| master-bin.000001 | 107 | Query | 1 | 264 | GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'172.16.1.2' IDENTIFIED BY 'replpass' |
| master-bin.000001 | 264 | Query | 1 | 339 | FLUSH PRIVILEGES |
+-------------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------------
3 rows in set (0.00 sec)
mysql> CHANGE MASTER TO MASTER_HOST='172.16.1.1',MASTER_USER='repluser',MASTER_PASSWORD='replpass',MASTER_LOG_FILE='master-bin.000001',MASTER_LOG_POS=339;
Query OK, 0 rows affected (0.05 sec)
�鿴slave������״̬��
mysql> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 172.16.1.1
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 339
Relay_Log_File: relay-log.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 339
Relay_Log_Space: 107
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
1 row in set (0.00 sec)
ERROR:
No query specified
����slave������
mysql> START SLAVE;
Query OK, 0 rows affected (0.00 sec)
�ٴβ鿴slave������״̬���鿴Slave_IO_Running��Slave_SQL_Running����״̬�ֱ�ΪYES,����slave������������
mysql> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.1.1
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 339
Relay_Log_File: relay-log.000002
Relay_Log_Pos: 254
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 339
Relay_Log_Space: 404
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
ERROR:
No query specified
3����master�����������ⴴ����ݿ⣬��slave��������֤����Ƿ�ͬ�����ƣ������slave�������Ͽ��Բ鿴��master��������������ݿ⣬�������Ƴɹ�
�鿴�Ѿ����ӵ�master��������slave������
mysql> SHOW SLAVE HOSTS;
+-----------+------+------+-----------+
| Server_id | Host | Port | Master_id |
+-----------+------+------+-----------+
| 11 | | 3306 | 1 |
+-----------+------+------+-----------+
1 row in set (0.00 sec)
����slave��������������������
�ı���read_only��ֵ���ñ�����SUPER�û���Ч
mysql> SHOW GLOBAL VARIABLES LIKE 'read_only';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only | OFF |
+---------------+-------+
1 row in set (0.00 sec)
# vim /etc/my.cnf
[mysqld]
read_only=ON
����mysqld����
# /etc/init.d/mysqld restart
mysql> SHOW GLOBAL VARIABLES LIKE 'read_only';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only | ON |
+---------------+-------+
1 row in set (0.00 sec)
mysqld�������������߳�Ҳ���Զ���������Ϊ��mysql���Ŀ¼�´���������ļ�master.info,relay-log.info
master.info�����ڱ�������master������ʱ���õ��û������룬master������IP����Ϣ
# cat master.info
18
master-bin.000001
422
172.16.1.1
repluser
replpass
3306
60
0
relay.info�����ڱ���master��������������־�ļ���Ƽ���λ�ã���slave���������м���־�ļ���λ��
# cat relay-log.info
./relay-log.000004
254
master-bin.000001
422
����master����������ͬ����������־�ļ�(����д����������д���������־�ļ�)
�ı���sync_binlog��ֵ
mysql> SHOW GLOBAL VARIABLES LIKE 'sync_binlog';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sync_binlog | 0 |
+---------------+-------+
1 row in set (0.00 sec)
# vim /etc/my.cnf
[mysqld]
sync_binlog=1
ʵ�ְ�ͬ������
��master�������ϰ�װsemisync_master.so���
��slave�������ϰ�װsemisync_slave.so���
1����master�������ϰ�װsemisync_master.so���
mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
Query OK, 0 rows affected (0.00 sec)
����rpl_semi_sync_master_enabled����
[mysqld]
rpl_semi_sync_master_enabled=ON
2����slave�������ϰ�װsemisync_slave.so���
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
Query OK, 0 rows affected (0.04 sec)
����rpl_semi_sync_slave_enabled ����
[mysqld]
rpl_semi_sync_slave_enabled=ON
����io_thread�߳�
mysql> STOP SLAVE io_thread;
mysql> START SLAVE io_thread;
��master�������ϲ鿴rpl���״̬����
mysql> SHOW GLOBAL STATUS LIKE '%rpl%';
+--------------------------------------------+-------------+
| Variable_name | Value |
+--------------------------------------------+-------------+
| Rpl_semi_sync_master_clients | 1 |
����������ֵ�����Կ�����ͬ���ͻ��˵�����Ϊ1
�ڰ�ͬ��ģ���£�ֻҪmaster��������slave������ͨ�Ų�����ϣ�master���������Զ�����Ϊ�첽
˫��ģ�ͣ�
1������̨�������ϸ��Խ���һ�����и���Ȩ���û���
2���������ļ� ��
master
[mysqld]
server-id=1
log-bin=master-bin
relay-log=relay-log
relay-log-index=relay-log.index
auto-increment-increment=2
auto-increment-offset=1
slave
[mysqld]
server-id=2
log-bin=master-bin
relay-log=relay-log
relay-log-index=relay-log.index
auto-increment-increment=2
auto-increment-offset=2
3������ʱ��̨��������Ϊ�½�������������д��������������ֻ���¼��ǰ�Լ���������־�ļ����¼�λ�� ����֮��Ϊ����ķ�����������ʼλ�ü���
mysql> SHOW MASTER STATUS;
4����������������ָ������һ̨������Ϊ�Լ���������������
master:
mysql> CHANGE MASTER TO
slave:
mysql> CHANGE MASTER TO
��ݹ��˸���
����master�е�ָ����ݿ⡢��ݱ?�Ƶ�slave������
ͨ������master����������slave����������ر���ʵ��
master������������
binlog-do-db: ����ָ������ݿ�д������¼����������־�ļ���ͬ����slave������
binlog-ignore-db
������ʹ��master�������������ã���Ϊ�ᵼ�¶�������־�ļ�������
slave����������
replicate-do-db��������ָ������ݿ�
replicate-ignore-db
�?����
replicate-do-table
replicate-ignore-table
ͨ��ʹ��ͨ���(% _)��ʾ�����
replicate-wild-do-table
replicate-wild-ignore-table
�������ļ������ñ�����ͨ��SHOW SLAVE STATUS\G;ָ�����Բ鿴�����˽��
MySQL 5.6ʵ�ָ���
GTID(Global Transaction Identifiers)��
��������UUID(128����ַ�)���ÿ�������ID��ɵı�ʶ�����ڱ�ʶÿһ������
������GTID������߿�����
���̸߳��ƣ�
slave�������������sql_thread�̣߳���ȡ�ж���־�ļ����ݣ����ͬ������
һ����ݿ�ֻ������һ���̣߳�������������߳�
slave-parallel-worker=# ָ���������߳����������ݿ����һ��
0����ʾ���ö��̸߳���
���ߣ�
mysqlreplicate����GTID����Ѿ�ִ�й������������slave������
mysqlrplcheck�� ��鸴�ƻ����Ƿ���������Ĺ���
mysqlrplshow�����ֲ���ɸ�������ͼ
mysqlfailover�������Զ������ֶ�����slave������Ϊmaster
mysqlrpladmin�����Թ��ߣ���ijһ��������down����up
MySQL 5.6��ʹ�ø��ƹ��ܣ�[mysqld]���ö�������Ӧ����������ѡ�
binlog-format����������־��ʽ����row,statement��mixedѡ�� ʹ��row����mixed
log-slave-updates: ��slave��������relay log�ж�ȡ�¼�ִ��ʱ���Ƿ��¼�����صĶ�������־
gitd-mode���Ƿ�����GTID����
enforce-gtid-consistency���Ƿ�ǿ��GTID����һ���Թ���
report-port:
report-host
master-info-repository: ������slave��������������Ϣ��¼���ļ��л��DZ���
relay-log-info-repository���ôӷ�������¼���ӵ�������������Ϣ����¼���ļ��л��DZ���
sync-master-info�����ÿ�ȷ������Ϣ��ʧ
slave-paralles-workers�����ôӷ�������SQL�߳���
binlog-checksum,master-verify-checksum,slave-sql-verify-checksum�����ø����йص�����У�鹦��
binlog-rows-query-log-events������֮�������ڶ�������־��¼�¼������Ϣ,�ɽ������ų�ĸ��Ӷ�
log-bin�����ö�������־
server-id ��ͬһ���������������з�������id�ű���Ωһ
һ��������ģʽ���ò���
1���������ӽڵ�������ļ�
master
[mysqld]
binlog-format=ROW
log-bin=master-bin
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=1
report-port=3306
port=3306
datadir=/mydata/data
socket=/tmp/mysql.sock
report-host=10.1.1.1
slave
[mysqld]
binlog-format=ROW
log-bin=master-bin
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=11
report-host=10.1.1.2
report-port=3306
port=3306
datadir=/mydata/data
socket=/tmp/mysql.socket
2����master�ڵ㴴�����и���Ȩ���û�
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'10.1.1.2' IDENTIFIED BY 'replpass';
mysql> FLUSH PRIVILEGES;
3����slave�ڵ�����master��������������slave�ڵ�
mysql> CHANGE MASTER TO MASTER_HOST='10.1.1.1',MASTER_USER='repluser',MASTER_PASSWORD='replpass',MASTER_AUTO_POSITION=1;
mysql> START SLAVE;
MySQL�����
MySQL Proxy
����lua�ű�ʵ�ֶ�д���롢��ѯ���˺��ġ����ؾ�⡢HA
Amoeba(Java)
ʵ�ֶ�д���롢��ѯ���˺��ġ����ؾ�⡢HA
xml��ʽ�����ļ�
Cobar(Java)
�ֿ⡢�ֱ�
MySQL Proxy��װ����
��10.1.1.3�ϰ�װMySQL Proxyͨ�ö����������ʵ�ֶ�д����
1�����������û�
# useradd mysql-proxy
2����װMySQL proxy���
# tar zxf mysql-proxy-0.8.3-linux-glibc2.3-x86-32bit.tar.gz -C /usr/local/
# cd /usr/local/
# ln -sv mysql-proxy-0.8.3-linux-glibc2.3-x86-32bit/ mysql-proxy
"mysql-proxy" -> "mysql-proxy-0.8.3-linux-glibc2.3-x86-32bit/"
# vim /etc/bashrc
export PATH=$PATH:/usr/local/mysql-proxy/bin
# source /etc/bashrc
3������mysql-proxy
# mysql-proxy --proxy-address=0.0.0.0:3306 --proxy-read-only-backend-addresses=10.1.1.2:3306 --proxy-backend-addresses=10.1.1.1:3306 --proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua --daemon --plugins=proxy --plugins=admin --log-level=debug --log-file=/var/log/mysql-proxy.log --admin-username=admin --admin-password=admin --admin-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/admin.lua
# tail /var/log/mysql-proxy.log
2015-12-20 19:19:06: (critical) plugin proxy 0.8.3 started
2015-12-20 19:19:06: (critical) plugin admin 0.8.3 started
2015-12-20 19:19:06: (debug) max open file-descriptors = 1024
2015-12-20 19:19:06: (message) proxy listening on port 0.0.0.0:3306
2015-12-20 19:19:06: (message) added read/write backend: 10.1.1.1:3306
2015-12-20 19:19:06: (message) added read-only backend: 10.1.1.2:3306
# netstat -antp | grep mysql-proxy
tcp 0 0 0.0.0.0:4041 0.0.0.0:* LISTEN 5698/mysql-proxy
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 5698/mysql-proxy
����ѡ��˵����
--proxy-address=0.0.0.0:3306 ָ��MySQL��������IP��ַ���˿� , Ĭ�϶˿�Ϊ4040
--proxy-read-only-backend-addresses=10.1.1.2:3306 ָ��ֻ��MySQL��������IP��ַ���˿�
--proxy-backend-addresses=10.1.1.1:3306 ָ���ɶ���дmysql��������IP��ַ���˿�
--proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua ָ������ʵ�ֶ���д���빦�ܵ�lua�ű�
--daemon�����ػ���̵ķ�ʽ����mysql-proxy
--plugins=proxy ָ��ʹ��proxy����ģ��
--plugins=admin ָ��ʹ��admin����ģ��
--admin-username=admin ָ����¼����ģ����û���
--admin-password=admin ָ����¼����ģ�������
--admin-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/admin.lua ָ������ģ��ʹ�õ�lua�ű�
--log-level=debug ָ����¼����־����
--log-file=/var/log/mysql-proxy.log ָ��mysql proxy����ʱ����־�ļ�
4�����Զ���д���빦��
��10.1.1.1 Master�������ϴ�����Զ�̵�¼�Ĺ���Ա�˺�
mysql> GRANT ALL ON *.* TO 'root'@'10.1.1.%' IDENTIFIED BY 'redhat';
mysql> FLUSH PRIVILEGES;
��10.1.1.2��Ϊ����һ���ͻ��ˣ����Ӵ�������������Զ�д���빦��
��10.1.1.2����root�û���¼�������������ִ�д�����ݿ��ָ��
# mysql -u root -p -h 10.1.1.3 -e 'CREATE DATABASE fe;'
Enter password:
�Թ����û�admin��¼10.1.1.3�ϵĹ�����棬�鿴��˷�����״̬������10.1.1.1��״̬ת��ΪUP������д���������䵽��10.1.1.1��
# mysql -u admin -p -h 10.1.1.3 --port=4041
mysql> SELECT * FROM backends;
+-------------+---------------+---------+------+------+-------------------+
| backend_ndx | address | state | type | uuid | connected_clients |
+-------------+---------------+---------+------+------+-------------------+
| 1 | 10.1.1.1:3306 | up | rw | NULL | 0 |
| 2 | 10.1.1.2:3306 | unknown | ro | NULL | 0 |
+-------------+---------------+---------+------+------+-------------------+
2 rows in set (0.00 sec)
��10.1.1.2����root�û���¼�������������ִ�в�ѯ����
MySQL Proxy����lua�ű� ��
function set_error(errmsg)
proxy.response = {
type = proxy.MYSQLD_PACKET_ERR,
errmsg = errmsg or "error"
}
end
function read_query(packet)
if packet:byte() ~= proxy.COM_QUERY then
set_error("[admin] we only handle text-based queries (COM_QUERY)")
return proxy.PROXY_SEND_RESULT
end
local query = packet:sub(2)
local rows = { }
local fields = { }
if query:lower() == "select * from backends" then
fields = {
{ name = "backend_ndx",
type = proxy.MYSQL_TYPE_LONG },
{ name = "address",
type = proxy.MYSQL_TYPE_STRING },
{ name = "state",
type = proxy.MYSQL_TYPE_STRING },
{ name = "type",
type = proxy.MYSQL_TYPE_STRING },
{ name = "uuid",
type = proxy.MYSQL_TYPE_STRING },
{ name = "connected_clients",
type = proxy.MYSQL_TYPE_LONG },
}
for i = 1, #proxy.global.backends do
local states = {
"unknown",
"up",
"down"
}
local types = {
"unknown",
"rw",
"ro"
}
local b = proxy.global.backends[i]
rows[#rows + 1] = {
i,
b.dst.name, -- configured backend address
states[b.state + 1], -- the C-id is pushed down starting at 0
types[b.type + 1], -- the C-id is pushed down starting at 0
b.uuid, -- the MySQL Server's UUID if it is managed
b.connected_clients -- currently connected clients
}
end
elseif query:lower() == "select * from help" then
fields = {
{ name = "command",
type = proxy.MYSQL_TYPE_STRING },
{ name = "description",
type = proxy.MYSQL_TYPE_STRING },
}
rows[#rows + 1] = { "SELECT * FROM help", "shows this help" }
rows[#rows + 1] = { "SELECT * FROM backends", "lists the backends and their state" }
else
set_error("use 'SELECT * FROM help' to see the supported commands")
return proxy.PROXY_SEND_RESULT
end
proxy.response = {
type = proxy.MYSQLD_PACKET_OK,
resultset = {
fields = fields,
rows = rows
}
}
return proxy.PROXY_SEND_RESULT
end
���ij��� ������ЦЦ���� ���ͣ�����ر����˳���http://hashlinux.blog.51cto.com/9647696/1760554