proxysql的作用
站在用戶的角度思考問題,與客戶深入溝通,找到南沙網(wǎng)站設(shè)計(jì)與南沙網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋南沙地區(qū)。
1.讀寫分離,server可以進(jìn)行分讀組和寫組
2.動(dòng)態(tài)指定某一個(gè)SQL進(jìn)行cache
3.故障切換,依賴于他的配置動(dòng)態(tài)加載,但是不能自動(dòng)選主,需要依賴keepalived和MHA
4.配置動(dòng)態(tài)更新
5.一個(gè)節(jié)點(diǎn)可以跑很多proxysql
6.percona公司的proxy
proxysql端口
監(jiān)控的端口號(hào):6633
管理端口號(hào):6032
安裝下載
[root@Darren1 tmp]# wgethttps://github.com/sysown/proxysql/releases/download/v1.4.0/proxysql-1.4.0-1-centos67.x86_64.rpm
[root@Darren1 tmp]# rpm -ivh proxysql-1.4.0-1-centos67.x86_64.rpm
[root@Darren1 tmp]# /etc/init.d/proxysql start
[root@Darren1 tmp]# ps -ef |grep proxy
root 50769 1 0 05:19 ? 00:00:00 proxysql -c /etc/proxysql.cnf -D /var/lib/proxysql
root 50770 50769 3 05:19 ? 00:00:00 proxysql -c /etc/proxysql.cnf -D /var/lib/proxysql
root 50798 50261 0 05:20 pts/3 00:00:00 grep proxy
#登陸:
[root@Darren1 proxysql]# MySQL -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
Admin> show databases;
+-----+---------+-------------------------------+
| seq | name | file |
+-----+---------+-------------------------------+
| 0 | main | |
| 2 | disk | /var/lib/proxysql/proxysql.db |
| 3 | stats | |
| 4 | monitor | |
+-----+---------+-------------------------------+
多層配置系統(tǒng)
(1)允許自動(dòng)更新配置
(2)大部分配置無需重啟,在運(yùn)行狀態(tài)配置生效
(3)允許回滾錯(cuò)誤的配置
三層結(jié)構(gòu)圖:
[1] LOAD MYSQL USERS FROM MEMORY / LOAD MYSQL USERS TO RUNTIME
loads MySQL users from the in-memory database to the runtime data structures
[2] SAVE MYSQL USERS TO MEMORY / SAVE MYSQL USERS FROM RUNTIME
persists the MySQL users from the runtime data structures to the in-memory database
[3] LOAD MYSQL USERS TO MEMORY / LOAD MYSQL USERS FROM DISK
loads MySQL users from the on-disk database to the in-memory database
[4] SAVE MYSQL USERS FROM MEMORY / SAVE MYSQL USERS TO DISK
persists the MySQL users from the in-memory database to the on-disk database
[5] LOAD MYSQL USERS FROM CONFIG
loads from the configuration file the users into the in-memory database
適用于表:
mysql_users mysql_servers
mysql_query_rules
mysql_variables
admin_variables
scheduler計(jì)劃任務(wù)
scheduler是類似cron的任務(wù)調(diào)度計(jì)劃,允許運(yùn)行自定義腳本。
主要有兩個(gè)表:
admin@127.0.0.1 [main]>SHOW TABLES LIKE '%scheduler%';
+-------------------+
| tables |
+-------------------+
| scheduler |
| runtime_scheduler |
+-------------------+
scheduler :可以用來設(shè)置調(diào)度計(jì)劃
runtime_scheduler:只讀,不能配置修改
admin@127.0.0.1 [main]> SHOW CREATE TABLE scheduler\G
*************************** 1. row ***************************
table: scheduler
Create Table: CREATE TABLE scheduler (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
interval_ms INTEGER CHECK (interval_ms>=100 AND interval_ms<=100000000) NOT NULL,
filename VARCHAR NOT NULL,
arg1 VARCHAR,
arg2 VARCHAR,
arg3 VARCHAR,
arg4 VARCHAR,
arg5 VARCHAR,
comment VARCHAR NOT NULL DEFAULT '')
In details:
id : unique identifier of the scheduler job
active : if set to 1, the job is active. Otherwise is not
interval_ms : how often (in millisecond) the job will be started. Minimum interval_ms is 100 milliseconds
filename : full path of the executable to be executed
arg1 to arg5 : arguments (maximum 5) that can be passed to the job
comment : an free form text field to annotate the purpose of the job
用戶配置Users Configuration
定義一個(gè)新的用戶:
admin@127.0.0.1 [main]>INSERT INTO mysql_users(username,password) VALUES ('user1','password1');
創(chuàng)建一個(gè)由hostgroup,schema的用戶:
admin@127.0.0.1 [main]>INSERT INTO mysql_users(username,password,default_hostgroup,default_schema) VALUES ('user2','password2',10,'sbtest1');
修改user2用戶的最大連接數(shù)為100個(gè):
admin@127.0.0.1 [main]>UPDATE mysql_users SET max_connections=100 WHERE username='user2';
修改事務(wù)持久化:
admin@127.0.0.1 [main]> UPDATE mysql_users SET transaction_persistent=1 WHERE username='user2';
密碼hash加密:
admin@127.0.0.1 [main]>load mysql users to runtime;
admin@127.0.0.1 [main]>save mysql users from runtime;
admin@127.0.0.1 [main]>save mysql users to disk;
服務(wù)配置 (server configuration )
1、往mysql_servers表中添加server時(shí)就為其劃分好hostgroup_id(例如0表示寫組,1表示讀組)
2、往mysql_servers表中添加server時(shí)不區(qū)分hostgroup_id(例如全部設(shè)為0),然后通過mysql_replication_hostgroups表中的值,根據(jù)proxysql檢測(cè)到的各server的read_only變量值來自動(dòng)為后端server設(shè)置hostgroup_id
強(qiáng)烈推薦用第一種方式: 因?yàn)榈谝环N是完全由我們控制的;而第二種假如我們誤將讀server的read_only屬性設(shè)置為0,則proxysql會(huì)將其重新分配到寫組,這絕對(duì)是不期望的。
(1)添加一個(gè)新的服務(wù):
admin@127.0.0.1 [main]>insert into mysql_servers(hostgroup_id,hostname,max_connections) values(0,'192.168.91.23',1000);
admin@127.0.0.1 [main]>insert into mysql_servers(hostgroup_id,hostname,max_connections) values(1,'192.168.91.22',1000);
admin@127.0.0.1 [(none)]>select * from mysql_servers;
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 0 | 192.168.91.23 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
| 1 | 192.168.91.22 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
(2)修改限制連接數(shù)max_connections :
admin@127.0.0.1 [main]>UPDATE mysql_servers SET max_connections=10 WHERE hostname='192.168.91.23';
(3)修改權(quán)重值weight:
例如:一主兩從的環(huán)境,設(shè)置不同的權(quán)重:
Admin> SELECT hostgroup_id,hostname,weight,max_replication_lag FROM mysql_servers;
+--------------+------------+--------+---------------------+
| hostgroup_id | hostname | weight | max_replication_lag |
+--------------+------------+--------+---------------------+
| 0 | 172.16.0.1 | 1000 | 30 |
| 1 | 172.16.0.2 | 1000 | 30 |
| 1 | 172.16.0.3 | 1000 | 30 |
| 1 | 172.16.0.1 | 1 | 30 |
+--------------+------------+--------+---------------------+
上面的情況,如果有讀事物,99.95%將會(huì)發(fā)送給172.16.0.2和172.16.0.3主機(jī)上,0.05%會(huì)發(fā)送到172.16.0.1主機(jī)上,如果172.16.0.2和172.16.0.3變得不可用了,則所有的讀會(huì)有172.16.0.1承擔(dān)
(4)修改復(fù)制延時(shí)最大值max_replication_lag :
admin@127.0.0.1 [main]>UPDATE mysql_servers SET max_replication_lag=30 WHERE hostname='192.168.91.23';
(5)打開壓縮,把compression設(shè)置為非0
admin@127.0.0.1 [main]>UPDATE mysql_servers SET compression=2 WHERE hostname='192.168.91.23';
(6)優(yōu)雅的關(guān)閉一個(gè)服務(wù):
把狀態(tài)改變成 status = offline_soft.
admin@127.0.0.1 [main]>UPDATE mysql_servers SET status='OFFLINE_SOFT' WHERE hostname='192.168.91.23';
(7)刪除一個(gè)服務(wù)delete即可
在proxysql連接msyql server
[root@Darren1 ~]# mysql -u admin -padmin -h 127.0.0.1 -P6032
#配置DB主機(jī):
admin@127.0.0.1 [main]>insert into mysql_servers(hostgroup_id,hostname) values(0,'192.168.91.23');
admin@127.0.0.1 [main]>insert into mysql_servers(hostgroup_id,hostname) values(1,'192.168.91.22');
admin@127.0.0.1 [(none)]>select * from mysql_servers;
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 0 | 192.168.91.23 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
| 1 | 192.168.91.22 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
#在mysql主庫(kù)上創(chuàng)建監(jiān)控用戶:
root@localhost [(none)]>create user monitor@'192.168.91.%' identified by 'monitor';
root@localhost [(none)]>grant all on *.* to monitor@'192.168.91.%';
#在proxysql中配置監(jiān)控用戶和密碼:
admin@127.0.0.1 [(none)]>UPDATE global_variables SET variable_value='monitor' WHERE variable_name='mysql-monitor_username';
admin@127.0.0.1 [(none)]>UPDATE global_variables SET variable_value='monitor' WHERE variable_name='mysql-monitor_password';
#配置監(jiān)控時(shí)間間隔:如mysql-monitor_connect_interval、 mysql-monitor_ping_interval、 mysql-monitor_read_only_interval:
admin@127.0.0.1 [(none)]>UPDATE global_variables SET variable_value='2000' WHERE variable_name IN ('mysql-monitor_connect_interval','mysql-monitor_ping_interval','mysql-monitor_read_only_interval');
admin@127.0.0.1 [(none)]>select * from global_variables where variable_name like 'mysql-monitor_%';
+-----------------------------------------------------+----------------+
| variable_name | variable_value |
+-----------------------------------------------------+----------------+
| mysql-monitor_enabled | true |
| mysql-monitor_connect_timeout | 600 |
| mysql-monitor_ping_max_failures | 3 |
| mysql-monitor_ping_timeout | 1000 |
| mysql-monitor_replication_lag_interval | 10000 |
| mysql-monitor_replication_lag_timeout | 1000 |
| mysql-monitor_groupreplication_healthcheck_interval | 5000 |
| mysql-monitor_groupreplication_healthcheck_timeout | 800 |
| mysql-monitor_username | monitor |
| mysql-monitor_password | monitor |
| mysql-monitor_query_interval | 60000 |
| mysql-monitor_query_timeout | 100 |
| mysql-monitor_slave_lag_when_null | 60 |
| mysql-monitor_wait_timeout | true |
| mysql-monitor_writer_is_also_reader | true |
| mysql-monitor_history | 600000 |
| mysql-monitor_connect_interval | 2000 |
| mysql-monitor_ping_interval | 2000 |
| mysql-monitor_read_only_interval | 2000 |
| mysql-monitor_read_only_timeout | 500 |
+-----------------------------------------------------+----------------+
admin@127.0.0.1 [(none)]>LOAD MYSQL VARIABLES TO RUNTIME;
admin@127.0.0.1 [(none)]>SAVE MYSQL VARIABLES TO DISK;
admin@127.0.0.1 [(none)]>show tables from monitor;
+------------------------------------+
| tables |
+------------------------------------+
| mysql_server_connect |
| mysql_server_connect_log |
| mysql_server_group_replication_log |
| mysql_server_ping |
| mysql_server_ping_log |
| mysql_server_read_only_log |
| mysql_server_replication_lag_log |
+------------------------------------+
admin@127.0.0.1 [(none)]>SELECT * FROM monitor.mysql_server_connect_log ORDER BY time_start_us DESC LIMIT 10;
+---------------+------+------------------+-------------------------+---------------+
| hostname | port | time_start_us | connect_success_time_us | connect_error |
+---------------+------+------------------+-------------------------+---------------+
| 192.168.91.23 | 3306 | 1495445436268761 | 1894 | NULL |
| 192.168.91.22 | 3306 | 1495445436267947 | 3301 | NULL |
| 192.168.91.23 | 3306 | 1495445434267631 | 601 | NULL |
| 192.168.91.22 | 3306 | 1495445434266684 | 1898 | NULL |
| 192.168.91.23 | 3306 | 1495445432267286 | 527 | NULL |
| 192.168.91.22 | 3306 | 1495445432266457 | 1646 | NULL |
+---------------+------+------------------+-------------------------+---------------+
admin@127.0.0.1 [(none)]>SELECT * FROM monitor.mysql_server_ping_log ORDER BY time_start_us DESC LIMIT 10;
+---------------+------+------------------+----------------------+------------+
| hostname | port | time_start_us | ping_success_time_us | ping_error |
+---------------+------+------------------+----------------------+------------+
| 192.168.91.23 | 3306 | 1495445542307107 | 147 | NULL |
| 192.168.91.22 | 3306 | 1495445542306299 | 504 | NULL |
| 192.168.91.23 | 3306 | 1495445540306625 | 173 | NULL |
| 192.168.91.22 | 3306 | 1495445540305786 | 596 | NULL |
| 192.168.91.23 | 3306 | 1495445538305981 | 165 | NULL |
+---------------+------+------------------+----------------------+------------+
admin@127.0.0.1 [(none)]>LOAD MYSQL SERVERS TO RUNTIME;
MySQL replication hostgroups
對(duì)應(yīng)表 mysql_replication_hostgroups
表的作用:配置寫組(比如1)和讀組(比如2),ProxySQL會(huì)根據(jù)read_only參數(shù)把主機(jī)分配到對(duì)應(yīng)的讀組合寫組中
如read_only=0 ,分配到hostgroup 1
如read_only=1 , 分配到 hostgroup 2
admin@127.0.0.1 [(none)]>INSERT INTO mysql_replication_hostgroups(writer_hostgroup,reader_hostgroup) VALUES (1,2);
admin@127.0.0.1 [(none)]>select * from mysql_replication_hostgroups;
+------------------+------------------+---------+
| writer_hostgroup | reader_hostgroup | comment |
+------------------+------------------+---------+
| 1 | 2 | NULL |
+------------------+------------------+---------+
#現(xiàn)在192.168.91.22是read_only=0,所以hostgroup_id=1:
admin@127.0.0.1 [(none)]>SELECT * FROM mysql_servers;
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 0 | 192.168.91.23 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
| 1 | 192.168.91.22 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
admin@127.0.0.1 [(none)]>load mysql servers to runtime;
root@localhost [(none)]>set global read_only=1;
admin@127.0.0.1 [(none)]>SELECT * FROM monitor.mysql_server_read_only_log ORDER BY time_start_us DESC LIMIT 10;
+---------------+------+------------------+-----------------+-----------+-------+
| hostname | port | time_start_us | success_time_us | read_only | error |
+---------------+------+------------------+-----------------+-----------+-------+
| 192.168.91.22 | 3306 | 1495449784913364 | 10240 | 1 | NULL |
| 192.168.91.22 | 3306 | 1495449782913147 | 3161 | 1 | NULL |
| 192.168.91.22 | 3306 | 1495449780912973 | 5600 | 1 | NULL |
| 192.168.91.22 | 3306 | 1495449778913003 | 8661 | 1 | NULL | |
+---------------+------+------------------+-----------------+-----------+-------+
#現(xiàn)在192.168.91.22是read_only=1,所以被分配到hostgroup_id=2:
admin@127.0.0.1 [(none)]>select * from mysql_servers;
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 0 | 192.168.91.23 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
| 2 | 192.168.91.22 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
+--------------+---------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
admin@127.0.0.1 [(none)]>SAVE MYSQL SERVERS TO DISK;
admin@127.0.0.1 [(none)]>save mysql variables to disk;
mysql_users
admin>INSERT INTO mysql_users(username,password,default_hostgroup) VALUES ('user1','147258',0);
admin>INSERT INTO mysql_users(username,password,default_hostgroup) VALUES ('user2','147258',1);
admin>INSERT INTO mysql_users(username,password,default_hostgroup) VALUES ('user3','147258',2);
admin@127.0.0.1 [(none)]>load mysql users to runtime;
admin@127.0.0.1 [(none)]>save mysql users to disk;
#需要在數(shù)據(jù)庫(kù)層面創(chuàng)建對(duì)應(yīng)的用戶名和密碼才能登陸操作數(shù)據(jù)庫(kù):
root@localhost [(none)]>create user user1@'%' identified by '147258';
root@localhost [(none)]>grant all on *.* to user1@'%';
mysql -u user1 -p147258 -h 127.0.0.1 -P6033
user1@127.0.0.1 [testdb]>select @@hostname;
+------------+
| @@hostname |
+------------+
| Darren1 |
+------------+
#可以用sysbench做測(cè)試:
[root@Darren1 ~]# sysbench --time=20 --threads=4 --mysql-host=localhost --mysql-user=user1 --mysql-password='147258' --mysql-port=6033 --mysql-db=sbtest --tables=4 --table_size=1000 /home/mysql/sysbench-1.0.3/src/lua/oltp_read_write.lua prepare
[root@Darren1 ~]# sysbench --time=20 --threads=4 --mysql-host=localhost --mysql-user=user1 --mysql-password='147258' --mysql-port=6033 --mysql-db=sbtest --tables=4 --table_size=1000 /home/mysql/sysbench-1.0.3/src/lua/oltp_read_write.lua run
ProxySQL Statistics
ProxySQL可以通過stats庫(kù)收集大量統(tǒng)計(jì)信息
admin@127.0.0.1 [(none)]>show tables from stats;
+-----------------------------------+
| tables |
+-----------------------------------+
| global_variables |
| stats_mysql_commands_counters |
| stats_mysql_connection_pool |
| stats_mysql_connection_pool_reset |
| stats_mysql_global |
| stats_mysql_processlist |
| stats_mysql_query_digest |
| stats_mysql_query_digest_reset |
| stats_mysql_query_rules |
| stats_mysql_users |
+-----------------------------------+
#stats.stats_mysql_connection_pool表:
admin@127.0.0.1 [(none)]>SELECT * FROM stats.stats_mysql_connection_pool;
+-----------+---------------+----------+--------+----------+----------+--------+---------+---------+-----------------+-----------------+------------+
| hostgroup | srv_host | srv_port | status | ConnUsed | ConnFree | ConnOK | ConnERR | Queries | Bytes_data_sent | Bytes_data_recv | Latency_us |
+-----------+---------------+----------+--------+----------+----------+--------+---------+---------+-----------------+-----------------+------------+
| 0 | 192.168.91.23 | 3306 | ONLINE | 0 | 0 | 0 | 22 | 0 | 0 | 0 | 168 |
| 2 | 192.168.91.22 | 3306 | ONLINE | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 926 |
| 1 | 192.168.91.22 | 3306 | ONLINE | 0 | 0 | 0 | 176 | 0 | 0 | 0 | 926 |
+-----------+---------------+----------+--------+----------+----------+--------+---------+---------+-----------------+-----------------+------------+
#stats_mysql_commands_counters表:
作用:
returns detailed information about the type of statements executed, and the distribution of execution time!
#統(tǒng)計(jì)一些sql的操作:
admin@127.0.0.1 [(none)]>select * from stats_mysql_commands_counters;
+-------------------+---------------+-----------+-----------+-----------+---------+---------+----------+----------+-----------+-----------+--------+--------+---------+----------+
| Command | Total_Time_us | Total_cnt | cnt_100us | cnt_500us | cnt_1ms | cnt_5ms | cnt_10ms | cnt_50ms | cnt_100ms | cnt_500ms | cnt_1s | cnt_5s | cnt_10s | cnt_INFs |
+-------------------+---------------+-----------+-----------+-----------+---------+---------+----------+----------+-----------+-----------+--------+--------+---------+----------+
| ALTER_TABLE | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| ALTER_VIEW | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| ANALYZE_TABLE | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BEGIN | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| CALL | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| CHANGE_MASTER | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| COMMIT | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
...........
#stats_mysql_query_digest查看執(zhí)行過的查詢操作
admin@127.0.0.1 [(none)]>SELECT * FROM stats_mysql_query_digest ORDER BY sum_time DESC;
+-----------+--------------------+----------+--------------------+-----------------------------------+------------+------------+------------+----------+----------+----------+
| hostgroup | schemaname | username | digest | digest_text | count_star | first_seen | last_seen | sum_time | min_time | max_time |
+-----------+--------------------+----------+--------------------+-----------------------------------+------------+------------+------------+----------+----------+----------+
| 0 | information_schema | user1 | 0x1E092DAEFFBBF262 | select ? | 1 | 1495462584 | 1495462584 | 111316 | 111316 | 111316 |
| 0 | testdb | user1 | 0x3765930C7143F468 | select * from t1 | 1 | 1495462644 | 1495462644 | 101438 | 101438 | 101438 |
| 0 | information_schema | user1 | 0x99531AEFF718C501 | show tables | 2 | 1495462594 | 1495
.......
#查詢表stats_mysql_query_digest_reset的作用就是把表stats_mysql_query_digest清空
admin@127.0.0.1 [(none)]>select * from stats_mysql_query_digest_reset;
admin@127.0.0.1 [(none)]>select * from stats_mysql_query_digest;
Empty set (0.00 sec)
路由規(guī)則(MySQL Query Rules)
表: mysql_query_rules
作用:控制讀寫分離
表中:apply=1 means that no further rules are checked if there is a match
#創(chuàng)建一個(gè)rule:表示SELECT * FROM t1$開頭的SQL語句會(huì)通過hostgroup為0的主機(jī)執(zhí)行:
admin@127.0.0.1 [(none)]>INSERT INTO mysql_query_rules (rule_id,active,username,match_digest,destination_hostgroup,apply) VALUES (10,1,'user1','^SELECT * FROM t1$',0,1);
admin@127.0.0.1 [(none)]>LOAD MYSQL QUERY RULES TO RUNTIME;
[root@Darren1 lua]# mysql -u user1 -p147258 -h 127.0.0.1 -P6033
user1@127.0.0.1 [testdb]>select * from t1;
#可以看到前面的select語句分配到hostgroup為0的服務(wù)器上:
admin@127.0.0.1 [(none)]>SELECT hostgroup hg, sum_time, count_star, digest_text FROM stats_mysql_query_digest ORDER BY sum_time DESC;
+----+----------+------------+------------------+
| hg | sum_time | count_star | digest_text |
+----+----------+------------+------------------+
| 0 | 716 | 1 | select * from t1 |
+----+----------+------------+------------------+