mysql> delete from scheduler ; mysql> delete from mysql_servers; mysql> delete from mysql_users; mysql> delete from mysql_query_rules; mysql> delete from mysql_group_replication_hostgroups;
# 修改后,加载到RUNTIME,并保存到disk mysql> LOAD MYSQL VARIABLES TO RUNTIME; mysql> SAVE MYSQL VARIABLES TO DISK;
mysql> LOAD MYSQL SERVERS TO RUNTIME; mysql> SAVE MYSQL SERVERS TO DISK;
mysql> LOAD MYSQL USERS TO RUNTIME; mysql> SAVE MYSQL USERS TO DISK;
mysql> LOAD SCHEDULER TO RUNTIME; mysql> SAVE SCHEDULER TO DISK;
mysql> LOAD MYSQL QUERY RULES TO RUNTIME; mysql> SAVE MYSQL QUERY RULES TO DISK;
建立proxysql登录账号
在任意一个节点操作,会自动同步到其他节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 在10.128.1.41上执行 [root@mgr-node1 ~]# mysql -uroot -p ········· mysql> CREATE USER 'proxysql'@'%' IDENTIFIED BY 'Zxc,./123'; Query OK, 0 rows affected (0.07 sec)
mysql> GRANT ALL ON * . * TO 'proxysql'@'%'; Query OK, 0 rows affected (0.06 sec)
mysql> create user 'sbuser'@'%' IDENTIFIED BY 'Zxc,./123'; Query OK, 0 rows affected (0.04 sec)
mysql> GRANT ALL ON * . * TO 'sbuser'@'%'; Query OK, 0 rows affected (0.06 sec)
# 更改后,加载到RUNTIME,并保存到disk mysql> LOAD MYSQL SERVERS TO RUNTIME; Query OK, 0 rows affected (0.00 sec)
mysql> SAVE MYSQL SERVERS TO DISK; Query OK, 0 rows affected (0.31 sec)
# 测试能否登录数据库 报错的情况下 [root@proxy-sql ~]# mysql -uproxysql -pZxc,./123 -h 127.0.0.1 -P6033 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): ProxySQL Error: Access denied for user 'proxysql'@'127.0.0.1' (using password: YES)
# 解决方法 mysql> LOAD MYSQL VARIABLES TO RUNTIME; mysql> SAVE MYSQL VARIABLES TO DISK;
mysql> LOAD MYSQL SERVERS TO RUNTIME; mysql> SAVE MYSQL SERVERS TO DISK;
mysql> LOAD MYSQL USERS TO RUNTIME; mysql> SAVE MYSQL USERS TO DISK;
mysql> LOAD SCHEDULER TO RUNTIME; mysql> SAVE SCHEDULER TO DISK;
mysql> LOAD MYSQL QUERY RULES TO RUNTIME; mysql> SAVE MYSQL QUERY RULES TO DISK;
# 再次验证 因为后端三个mysql的MGR节点还没有加入到proxysql中的原因 [root@proxy-sql ~]# mysql -uproxysql -pZxc,./123 -h 127.0.0.1 -P6033 -e "select @@hostname" ERROR 9001 (HY000) at line 1: Max connect timeout reached while reaching hostgroup 1 after 10000ms
# 需要将global_variables,mysql_servers、mysql_users表的信息加载到RUNTIME,更进一步加载到DISK: mysql> LOAD MYSQL VARIABLES TO RUNTIME; mysql> SAVE MYSQL VARIABLES TO DISK;
mysql> LOAD MYSQL SERVERS TO RUNTIME; mysql> SAVE MYSQL SERVERS TO DISK;
mysql> LOAD MYSQL USERS TO RUNTIME; mysql> SAVE MYSQL USERS TO DISK;
# 再次验证proxysql登录 [root@proxy-sql ~]# mysql -uproxysql -pZxc,./123 -h 127.0.0.1 -P6033 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | mgr-node2 | +------------+ [root@proxy-sql ~]# mysql -uproxysql -pZxc,./123 -h 127.0.0.1 -P6033 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | mgr-node1 | +------------+
mysql> LOAD SCHEDULER TO RUNTIME; mysql> SAVE SCHEDULER TO DISK;
============================================================================== scheduler各column的说明: active : 1: enable scheduler to schedule the script we provide interval_ms : invoke one by one in cycle (eg: 5000(ms) = 5s represent every 5s invoke the script) filename: represent the script file path arg1~arg5: represent the input parameters the script received 脚本proxysql_groupreplication_checker.sh对应的参数说明如下: arg1 is the hostgroup_id for write 可写入组 arg2 is the hostgroup_id forread 可读取组 arg3 is the number of writers we want active at the same time 同时写入组 arg4 represents if we want that the member acting for writes is also candidate for reads 可写的节点是否用户可读 arg5 is the log file
mysql> LOAD MYSQL QUERY RULES TO RUNTIME; mysql> SAVE MYSQL QUERY RULES TO DISK;
rule_id ProxySQL是根据rule_id的顺序进行规则匹配的。 active表示是否启用这个sql路由项, match_pattern的规则是基于正则表达式的, destination_hostgroup表示我们要将该类sql转发到哪些mysql上面去,这里我们将select转发到group 2,select for update转发到group 1。 apply为1表示该正则匹配后,将不再接受其他匹配,直接转发。
# 在proxysql本机或其他客户机上检查下,select 语句,一直连接的是10.128.1.42和10.128.1.43 [root@mgr-node1 ~]# mysql -uproxysql -pZxc,./123 -h10.128.1.44 -P6033 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | mgr-node2 | +------------+
[root@mgr-node1 ~]# mysql -uproxysql -pZxc,./123 -h10.128.1.44 -P6033 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | mgr-node2 | +------------+
[root@mgr-node1 ~]# mysql -uproxysql -pZxc,./123 -h10.128.1.44 -P6033 -e "select * from kaka.kaka_test" mysql: [Warning] Using a password on the command line interface can be insecure. +----+-------+ | id | name | +----+-------+ | 1 | 223 | | 2 | 345 | | 15 | 44 | | 22 | 444 | | 23 | 344 | | 30 | 555 | | 37 | rtr | | 44 | dsfda | | 51 | dafd | | 58 | adsfd | +----+-------+
[root@mgr-node1 ~]# mysql -uproxysql -pZxc,./123 -h10.128.1.44 -P6033 -e "delete from kaka.kaka_test where id > 25;" [root@mgr-node1 ~]# mysql -uproxysql -pZxc,./123 -h10.128.1.44 -P6033 -e "delete from kaka.kaka_test where id=2;" [root@mgr-node1 ~]# mysql -uproxysql -pZxc,./123 -h10.128.1.44 -P6033 -e "select * from kaka.kaka_test" mysql: [Warning] Using a password on the command line interface can be insecure. +----+------+ | id | name | +----+------+ | 1 | 223 | | 15 | 44 | | 22 | 444 | | 23 | 344 | +----+------+
[root@mgr-node1 ~]# mysql -uproxysql -pZxc,./123 -h10.128.1.44 -P6033 -e 'insert into kaka.kaka_test values(31,"zhongguo"),(32,"xianggang"),(33,"taiwan");' [root@mgr-node1 ~]# mysql -uproxysql -pZxc,./123 -h10.128.1.44 -P6033 -e "select * from kaka.kaka_test" mysql: [Warning] Using a password on the command line interface can be insecure. +----+-----------+ | id | name | +----+-----------+ | 1 | 223 | | 15 | 44 | | 22 | 444 | | 23 | 344 | | 31 | zhongguo | | 32 | xianggang | | 33 | taiwan | +----+-----------+
#查看监控配置 select * from global_variables where variable_name like 'mysql-monitor%'; #检查ping select * FROM monitor.mysql_server_ping_log ORDER BY time_start_us DESC LIMIT 10; #mysql_server_connect_log select * FROM monitor.mysql_server_connect_log ORDER BY time_start_us DESC LIMIT 6;
# 可以修改监控时间间隔 UPDATE global_variables SET variable_value='2000' WHERE variable_name IN ('mysql-monitor_connect_interval','mysqlmonitor_ping_interval','mysql-monitor_read_only_interval');