读写分离的搭建流程及测试过程


环境简述:

ProxySql

100.192.192.205

proxysql

proxysql-2.6.3-1-centos7.x86_64

Mysql-Master

100.192.192.206

msyql-master

Ver 8.0.37

Mysql-Slave

100.192.192.207

mysql-slave

Ver 8.0.37

[root@localhost ~]# cat /etc/redhat-release  

Red Hat Enterprise Linux Server release 7.9 (Maipo)

[root@localhost tmp]# mysql --version

mysql  Ver 8.0.37 for Linux on x86_64 (MySQL Community Server - GPL)


1.安装/配置ProxySql

2.MySQL8.0读写分离


1.安装ProxySql,官方链接: https://repo.proxysql.com/ProxySQL/ProxySQL+Mysql实现数据库读写分离实战_MySQL

#安装proxysql需要perl支持,本地安装系统的原镜像中有所需的perl包
#所以是先挂在本地yum,安装下必备的两个包
#最后安装下载回来的ProxySQL
[root@localhost tmp]# ll
-rw-r--r-- 1 root root 18209796 Jun 26 13:43 proxysql-2.6.3-1-centos7.x86_64.rpm
[root@localhost tmp]# yum install perl-DBI.x86_64    -y          
[root@localhost tmp]# yum install perl-DBD-MySQL.x86_64      -y
[root@localhost tmp]# rpm -ivh proxysql-2.6.3-1-centos7.x86_64.rpm 

#proxysql.cnf中的配置只在初次启动proxysql时生效
#先改配置再启动

[root@localhost tmp]# systemctl restart proxysql
[root@localhost tmp]# systemctl status proxysql
● proxysql.service - High Performance Advanced Proxy for MySQL
   Loaded: loaded (/etc/systemd/system/proxysql.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-06-27 15:44:46 CST; 2s ago
  Process: 24924 ExecStart=/usr/bin/proxysql --idle-threads -c /etc/proxysql.cnf $PROXYSQL_OPTS (code=exited, status=0/SUCCESS)
 Main PID: 24928 (proxysql)
    Tasks: 25
   CGroup: /system.slice/proxysql.service
           ├─24928 /usr/bin/proxysql --idle-threads -c /etc/proxysql.cnf
           └─24929 /usr/bin/proxysql --idle-threads -c /etc/proxysql.cnf
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.

1.2 配置proxysql

proxysql有几个地方需要配置:

1.配置文件
默认配置文件位于/etc/proxysql.cnf,可以通过命令行参数-c指定配置文件
datadir指定了proxysql内置数据库的存放路径。
需要注意的是,proxysql.cnf中的配置只在初次启动proxysql时生效。
如果proxysql的内置数据库已经创建,则后续只会从内置数据库中读取配置信息,
此时再修改proxysql.cnf不起作用

datadir="/var/lib/proxysql"
errorlog="/var/lib/proxysql/proxysql.log"

admin_variables=
{
        admin_credentials="admin:admin"
#       mysql_ifaces="127.0.0.1:6032;/tmp/proxysql_admin.sock"
        mysql_ifaces="0.0.0.0:6032"           #管理端口
#       refresh_interval=2000
#       debug=true
}

mysql_variables=
{
        threads=4
        max_connections=2048
        default_query_delay=0
        default_query_timeout=36000000
        have_compress=true
        poll_timeout=2000
#       interfaces="0.0.0.0:6033;/tmp/proxysql.sock"
        interfaces="0.0.0.0:6033"              #业务分流端口
        default_schema="information_schema"
        stacksize=1048576
        server_version="5.5.30"
        connect_timeout_server=3000

2.配置数据库
proxysql的配置项以数据库表的形式存在,可以通过标准的SQL语句来配置。
使用mysql客户端登陆proxysql的admin端口,默认,使用标准的sql语句来配置参数。
admin端口由参数admin_variables mysql_ifaces指定,admin账号密码由参数admin_credentials指定。
admin账号只能在本地登陆。登陆后可以查看和修改配置项。

为了保证本地可以登录,可以先安装个mariadb
[root@localhost mysql]# yum -y install mariadb
只能本地登录,admin/admin
[root@localhost mysql]# mysql -uadmin -padmin -P6032 -h127.0.0.1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.30 (ProxySQL Admin Module)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+-----+---------------+-------------------------------------+
| seq | name          | file                                |
+-----+---------------+-------------------------------------+
| 0   | main          |                                     |
| 2   | disk          | /var/lib/proxysql/proxysql.db       |
| 3   | stats         |                                     |
| 4   | monitor       |                                     |
| 5   | stats_history | /var/lib/proxysql/proxysql_stats.db |
+-----+---------------+-------------------------------------+
5 rows in set (0.00 sec)

可见有五个库: main、disk、stats 、monitor 和 stats_history
main: 内存配置数据库,即 MEMORY,表里存放后端 db 实例、用户验证、路由规则等信息。
      这个库中的表分两类,runtime开头的表存的是当前实际生效的配置。
      其它表存的是配置值,可通过load命令加载到runtime中,通过save命令持久化。
disk:sqllite数据库。proxysql启动时从该数据库加载配置项。
stats: 统计信息的汇总
monitor:一些监控的收集信息,比如数据库的健康状态等
stats_history: 这个库是 ProxySQL 收集的有关其内部功能的历史指标

main库下的主要表:
mysql_servers: 后端可以连接 MySQL 服务器的列表
mysql_users: 配置后端数据库的账号和监控的账号。
mysql_query_rules: 指定 Query 路由到后端不同服务器的规则列表,配置查询路由规则。
    注:表名以 runtime_开头的表示 ProxySQL 当前运行的配置内容,不能通过 DML 语句修改。
    只能修改对应的不以 runtime 开头的表,然后 “LOAD” 使其生效,“SAVE” 使其存到硬盘以供下次重启加载。
mysql_replication_hostgroups	配置常规MySQL主备复制hostgroup。
mysql_group_replication_hostgroups		配置MySQL组复制hostgroup。
global_variables	  配置参数。参数分为admin参数和mysql参数两大类。
proxysql_servers		配置proxysql集群

save admin variables to disk;	
save mysql variables to disk;	
save proxysql servers to disk;
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.


3.使用proxysql,主要需要完成以下几项内容的配置:

1、配置监控账号。监控账号用于检测后端mysql实例是否健康(是否能连接、复制是否正常、复制是否有延迟等)。
2、到后端mysql实例创建监控账号。
3、配置后端mysql实例连接信息。实例连接信息存储在mysql_servers表。
4、配置连接proxysql和后端实例的账号。账号信息存储在mysql_users表。
5、配置查询路由信息。路由信息存储在mysql_query_rules表。
6、配置后端mysql集群信息。根据后端mysql集群架构,配置分别存储在
mysql_replication_hostgroups、mysql_group_replication_hostgroups、
runtime_mysql_galera_hostgroups、runtime_mysql_aws_aurora_hostgroups等表中。
7、根据具体需要,调优相关参数。参数存储在global_variables表。


3.1配置ProxySQL所需账户
proxysql使用监控账号来探测后端mysql实例的健康度。监控账号需要一些基本的权限,包括:
连接数据库、查看复制状态(replication client)、查看group replication相关表(performance_schema)

到后端mysql主库从库206/207中创建监控账号,所有的主从机都要建
create user 'monitor'@'%' identified with mysql_native_password by 'monitor';
grant replication client on *.* to 'monitor'@'%';
--group replication
grant select on performance_schema.replication_group_member_stats to 'monitor'@'%';
grant select on performance_schema.replication_group_members to 'monitor'@'%';

更省事的授权法子:
#proxysql 的监控账户,
create user 'monitor'@'%' identified with mysql_native_password by 'monitor';
grant all privileges on *.* to 'monitor'@'%' with grant option;



3.2 定义proxy读写分组
MySQL [(none)]> show create table mysql_replication_hostgroups \G  #表结构
*************************** 1. row ***************************
       table: mysql_replication_hostgroups
Create Table: CREATE TABLE mysql_replication_hostgroups (
    writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY,
    reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0),
    check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only','innodb_read_only','super_read_only','read_only|innodb_read_only','read_only&innodb_read_only')) NOT NULL DEFAULT 'read_only',
    comment VARCHAR NOT NULL DEFAULT '', UNIQUE (reader_hostgroup))
1 row in set (0.00 sec)

MySQL [(none)]> select * from mysql_replication_hostgroups\G;    ##初始内容为空
Empty set (0.00 sec)
ERROR: No query specified

MySQL [(none)]>  insert into 
mysql_replication_hostgroups (writer_hostgroup,reader_hostgroup,comment) 
values (1,0,'proxy');
Query OK, 1 row affected (0.00 sec)
MySQL [(none)]> load mysql servers to runtime;
Query OK, 0 rows affected (0.01 sec)
MySQL [(none)]> save mysql servers to disk;
Query OK, 0 rows affected (0.03 sec)

此处先定义好分组,后面会根据server my.cnf中的read_only的取值将服务器进行分组。
read_only=0的server,master被分到编号为1的写组,
read_only=1的server,slave则分到编号为0的读组

MySQL [(none)]> select * from  mysql_replication_hostgroups\G
MySQL [(none)]>  select * from  mysql_replication_hostgroups;
+------------------+------------------+------------+---------+
| writer_hostgroup | reader_hostgroup | check_type | comment |
+------------------+------------------+------------+---------+
| 1                | 0                | read_only  | proxy   |
+------------------+------------------+------------+---------+

添加主从服务器节点:
MySQL [(none)]> insert into mysql_servers(hostgroup_id,hostname,port) values (1,'10.92.132.206',3306);
Query OK, 1 row affected (0.000 sec)
MySQL [(none)]> insert into mysql_servers(hostgroup_id,hostname,port) values (0,'10.92.132.207',3306);
Query OK, 1 row affected (0.000 sec)
MySQL [(none)]> load mysql servers to runtime;
Query OK, 0 rows affected (0.002 sec)
MySQL [(none)]> save mysql servers to disk;
Query OK, 0 rows affected (0.015 sec)
MySQL [(none)]>  select * from mysql_servers;
+--------------+-----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname        | port | gtid_port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+-----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 1            | 100.192.192.206 | 3306 | 0         | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |
| 0            | 100.192.192.207 | 3306 | 0         | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |
+--------------+-----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+


3.2设置Proxy SQL监控账户  在proxysql操作
MySQL [(none)]> use monitor #使用monitor
Database changed
MySQL [monitor]> set mysql-monitor_username='monitor';  #创建用户 
Query OK, 1 row affected (0.000 sec)
MySQL [monitor]> set mysql-monitor_password='monitor'; #填写密码
Query OK, 1 row affected (0.000 sec)
MySQL [monitor]>  load mysql variables to runtime; #加载到当前
Query OK, 0 rows affected (0.001 sec)
MySQL [monitor]> save mysql variables to disk; #持久化保存
Query OK, 158 rows affected (0.003 sec)
MySQL [monitor]> select @@mysql-monitor_username; #查看用户名
+--------------------------+
| @@mysql-monitor_username |
+--------------------------+
| monitor                  |
+--------------------------+
1 row in set (0.001 sec)
MySQL [monitor]> select @@mysql-monitor_password; #查看密码
+--------------------------+
| @@mysql-monitor_password |
+--------------------------+
| Monitor@123.com          |
+--------------------------+
1 row in set (0.001 sec)

#如下看出,所有的主从库都需要配置monitor账户
MySQL [monitor]> select * from monitor.mysql_server_connect_log; #查看日志信息
+---------------+------+------------------+-------------------------+------------------------------------------------------------------------+
| hostname      | port | time_start_us    | connect_success_time_us | connect_error                                                          |
+---------------+------+------------------+-------------------------+------------------------------------------------------------------------+
| 10.------.207 | 3306 | 1719541847591020 | 0                       | Access denied for user 'monitor'@'10.------.205' (using password: YES) |
| 10.------.206 | 3306 | 1719541848751218 | 1361                    | NULL                                                                   |
| 10.------.207 | 3306 | 1719541907591480 | 0                       | Access denied for user 'monitor'@'10.------.205' (using password: YES) |
| 10.------.206 | 3306 | 1719541908557661 | 1373                    | NULL                                                                   |
| 10.------.207 | 3306 | 1719541967591783 | 0                       | Access denied for user 'monitor'@'10.------.205' (using password: YES) |
| 10.------.206 | 3306 | 1719541968550410 | 1370                    | NULL                                                                   |
| 10.------.206 | 3306 | 1719542027592162 | 1333                    | NULL                                                                   |
| 10.------.207 | 3306 | 1719542028272231 | 0                       | Access denied for user 'monitor'@'10.------.205' (using password: YES) |
| 10.------.206 | 3306 | 1719542087592593 | 1481                    | NULL                                                                   |
| 10.------.207 | 3306 | 1719542088204467 | 0                       | Access denied for user 'monitor'@'10.-------.205' (using password: YES) |
| 10.------.207 | 3306 | 1719542147593077 | 0                       | Access denied for user 'monitor'@'10.-------.205' (using password: YES) |
MySQL [monitor]> select * from mysql_server_ping_log; #查看心跳信息
+---------------+------+------------------+----------------------+------------------------------------------------------------------------+
| hostname      | port | time_start_us    | ping_success_time_us | ping_error                                                             |
+---------------+------+------------------+----------------------+------------------------------------------------------------------------+
| 10.------.206 | 3306 | 1719541899655171 | 354                  | NULL                                                                   |
| 10.------.207 | 3306 | 1719541899655272 | 0                    | Access denied for user 'monitor'@'10.---.---.205' (using password: YES) |
| 10.------.206 | 3306 | 1719541909655589 | 424                  | NULL                                                                   |
| 10.------.207 | 3306 | 1719541909655680 | 0                    | Access denied for user 'monitor'@'10.---.---.205' (using password: YES) |
| 10.------.206 | 3306 | 1719541919655978 | 391                  | NULL                                                                   |
| 10.------.207 | 3306 | 1719541919656064 | 0                    | Access denied for user 'monitor'@'10.---.---.205' (using password: YES) |
| 10.------.206 | 3306 | 1719541929656401 | 389                  | NULL                                                                   |
| 10.------.207 | 3306 | 1719541929656463 | 0                    | Access denied for user 'monitor'@'10.---.---.205' (using password: YES) |


proxysql配置对外访问账号:
MySQL [monitor]> insert into 
mysql_users(username,password,default_hostgroup,transaction_persistent) 
values ('proxysql','123456',1,1);
MySQL [monitor]> select * from mysql_users\G
*************************** 1. row ***************************
              username: proxysql
              password: 111111
                active: 1
               use_ssl: 0
     default_hostgroup: 1
        default_schema: NULL
         schema_locked: 0
transaction_persistent: 1
          fast_forward: 0
               backend: 1
              frontend: 1
       max_connections: 10000
            attributes: 
               comment: 
1 row in set (0.00 sec)

在从库192.168.27.139上通过对方询问账号proxysql连接,是否路由能默认到写组
[root@localhost tmp]#  mysql -h10.92.132.162 -uproxysql -p'111111' -P 6033
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.5.30 (ProxySQL)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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.

proxysql@db 11:35:  [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| hl                 |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.02 sec)

proxysql@db 11:35:  [(none)]> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|         361 |
+-------------+
1 row in set (0.00 sec)

proxysql@db 11:35:  [(none)]> 
proxysql@db 11:35:  [(none)]> use hl
Database changed
proxysql@db 11:39:  [hl]> show tables;
+--------------+
| Tables_in_hl |
+--------------+
| test         |
| testt        |
+--------------+
2 rows in set (0.00 sec)
proxysql@db 11:39:  [hl]> create table testtt as select * from test;
Query OK, 2 rows affected (0.04 sec)
Records: 2  Duplicates: 0  Warnings: 0
proxysql@db 11:39:  [hl]> show tables;
+--------------+
| Tables_in_hl |
+--------------+
| test         |
| testt        |
| testtt       |
+--------------+
3 rows in set (0.00 sec)
proxysql@db 11:39:  [hl]>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
添加简单的读写分离规则
MySQL [(none)]> insert into mysql_query_rules(rule_id,active,match_digest,destination_hostgroup,apply)
values(1,1,'^SELECT.*FOR UPDATE$',1,1);
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> insert into mysql_query_rules(rule_id,active,match_digest,destination_hostgroup,apply)
values(2,1,'^SELECT',0,1);
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> select rule_id,active,match_digest,destination_hostgroup,apply from mysql_query_rules;
+---------+--------+----------------------+-----------------------+-------+
| rule_id | active | match_digest         | destination_hostgroup | apply |
+---------+--------+----------------------+-----------------------+-------+
| 1       | 1      | ^SELECT.*FOR UPDATE$ | 1                     | 1     |
| 2       | 1      | ^SELECT              | 0                     | 1     |
+---------+--------+----------------------+-----------------------+-------+
2 rows in set (0.00 sec)

MySQL [monitor]> load mysql query rules to runtime;
Query OK, 0 rows affected (0.000 sec)
MySQL [monitor]> save mysql query rules to disk;
Query OK, 0 rows affected (0.006 sec)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.


4.测试读写分离
在proxysql上操作
本地使用MySQL命令行或者navicat都可以连接proxy SQL:6033端口

4.1写入数据
#在proxysql或者其他测试电脑上,连ProxySQL的6033端口,进入业务地址
#运行select 和insert 语句
#在ProxySQL上6032管理端口,查看stats_mysql_query_digest中语句的分配历史

[root@localhost mysql]# mysql -uproxysql -p111111 -P6033 -h127.0.0.1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.5.30 (ProxySQL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> 
MySQL [(none)]> insert into hl.test values(44,'xyxyxyx');
Query OK, 1 row affected (0.00 sec)
MySQL [(none)]>  select * from test;
ERROR 1109 (42S02): Unknown table 'TEST' in information_schema
MySQL [(none)]>  select * from hl.test;
+------+--------------+
| id   | name         |
+------+--------------+
|   11 | dfghh        |
|   22 | lkjhgfd      |
|   33 | asdfsadfasdf |
|   44 | xyxyxyx      |
+------+--------------+
4 rows in set (0.00 sec)


4.2管理端6032查看sql分配
[root@localhost mysql]# mysql -uadmin -padmin -P6032 -h127.0.0.1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.5.30 (ProxySQL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> 
MySQL [(none)]> select hostgroup,schemaname,username,digest_text,count_star from  stats_mysql_query_digest;
+-----------+--------------------+----------+--------------------------------------------------------------------------------------------------+------------+
| hostgroup | schemaname         | username | digest_text                                                                                      | count_star |
+-----------+--------------------+----------+--------------------------------------------------------------------------------------------------+------------+
| 0         | information_schema | proxysql | select hostgroup,schemaname,username,digest_text,count_star from stats_mysql_query_digest        | 1          |
| 0         | information_schema | proxysql | select * from test                                                                               | 1          |
| 1         | information_schema | proxysql | insert into hl.test values(?,?)                                                                  | 1          |
+-----------+--------------------+----------+--------------------------------------------------------------------------------------------------+------------+
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.