MyCat 管理命令与监控 详解

MyCat 自身有类似其他数据库的管理监控方式,可以通过 MySQL 命令行,登录管理端口(9066) 执行相应的 SQL 进行管理,也可以通过 jdbc 的方式进行远程连接管理。MyCat1.6 有两个端口,8066 数据端口,9066 管理端口,命令行的登陆是通过 9066 管理端口来操作,登录方式类似于 MySQL 的服务端登陆
# mysql -uroot -p123456 -h192.168.139.131 -P9066
-h 后面是主机,即当前 MyCat 按照的主机地址,本地可用 127.0.0.1 远程需要远程 ip
-u MyCat server.xml 中配置的逻辑库用户
-p MyCat server.xml 中配置的逻辑库密码
-P 后面是端口 默认 9066,注意 P 是大写
-d Mycat server.xml 中配置的逻辑库
数据端口与管理端口的配置端口修改 :
数据端口默认 8066,管理端口默认 9066 ,如果需要修改需要配置 serve.xml
  8067
  9066

命令总览 : 通过 show @@help; 可以查看所有的命令
mysql> show @@help;
+------------------------------------------+--------------------------------------------+
| STATEMENT                                | DESCRIPTION                                |
+------------------------------------------+--------------------------------------------+
| show @@time.current                      | Report current timestamp                   |
| show @@time.startup                      | Report startup timestamp                   |
| show @@version                           | Report Mycat Server version                |
| show @@server                            | Report server status                       |
| show @@threadpool                        | Report threadPool status                   |
| show @@database                          | Report databases                           |
| show @@datanode                          | Report dataNodes                           |
| show @@datanode where schema = ?         | Report dataNodes                           |
| show @@datasource                        | Report dataSources                         |
| show @@datasource where dataNode = ?     | Report dataSources                         |
| show @@datasource.synstatus              | Report datasource data synchronous         |
| show @@datasource.syndetail where name=? | Report datasource data synchronous detail  |
| show @@datasource.cluster                | Report datasource galary cluster variables |
| show @@processor                         | Report processor status                    |
| show @@command                           | Report commands status                     |
| show @@connection                        | Report connection status                   |
| show @@cache                             | Report system cache usage                  |
| show @@backend                           | Report backend connection status           |
| show @@session                           | Report front session details               |
| show @@connection.sql                    | Report connection sql                      |
| show @@sql.execute                       | Report execute status                      |
| show @@sql.detail where id = ?           | Report execute detail status               |
| show @@sql                               | Report SQL list                            |
| show @@sql.high                          | Report Hight Frequency SQL                 |
| show @@sql.slow                          | Report slow SQL                            |
| show @@sql.resultset                     | Report BIG RESULTSET SQL                   |
| show @@sql.sum                           | Report  User RW Stat                       |
| show @@sql.sum.user                      | Report  User RW Stat                       |
| show @@sql.sum.table                     | Report  Table RW Stat                      |
| show @@parser                            | Report parser status                       |
| show @@router                            | Report router status                       |
| show @@heartbeat                         | Report heartbeat status                    |
| show @@heartbeat.detail where name=?     | Report heartbeat current detail            |
| show @@slow where schema = ?             | Report schema slow sql                     |
| show @@slow where datanode = ?           | Report datanode slow sql                   |
| show @@sysparam                          | Report system param                        |
| show @@syslog limit=?                    | Report system mycat.log                    |
| show @@white                             | show mycat white host                      |
| show @@white.set=?,?                     | set mycat white host,[ip,user]             |
| show @@directmemory=1 or 2               | show mycat direct memory usage             |
| switch @@datasource name:index           | Switch dataSource                          |
| kill @@connection id1,id2,...            | Kill the specified connections             |
| stop @@heartbeat name:time               | Pause dataNode heartbeat                   |
| reload @@config                          | Reload basic config from file              |
| reload @@config_all                      | Reload all config from file                |
| reload @@route                           | Reload route config from file              |
| reload @@user                            | Reload user config from file               |
| reload @@sqlslow=                        | Set Slow SQL Time(ms)                      |
| reload @@user_stat                       | Reset show @@sql  @@sql.sum @@sql.slow     |
| rollback @@config                        | Rollback all config from memory            |
| rollback @@route                         | Rollback route config from memory          |
| rollback @@user                          | Rollback user config from memory           |
| reload @@sqlstat=open                    | Open real-time sql stat analyzer           |
| reload @@sqlstat=close                   | Close real-time sql stat analyzer          |
| offline                                  | Change MyCat status to OFF                 |
| online                                   | Change MyCat status to ON                  |
| clear @@slow where schema = ?            | Clear slow sql by schema                   |
| clear @@slow where datanode = ?          | Clear slow sql by datanode                 |
+------------------------------------------+--------------------------------------------+
58 rows in set (0.01 sec)

reload @@config : 重新加载配置文件
mysql> reload @@config;
Query OK, 1 row affected (0.11 sec)
Reload config success

show @@database : 显示 MyCAT 的数据库的列表,对应 schema.xml 配置文件的 schema 子节点
mysql> show @@database;
+----------+
| DATABASE |
+----------+
| TESTDB   |
+----------+
1 row in set (0.01 sec)

show @@datanode : 显示 MyCAT 的数据节点的列表,对应 schema.xml 配置文件的 dataNode 节点
mysql> show @@datanode;
+------+----------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
| NAME | DATHOST        | INDEX | TYPE  | ACTIVE | IDLE | SIZE | EXECUTE | TOTAL_TIME | MAX_TIME | MAX_SQL | RECOVERY_TIME |
+------+----------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
| dn1  | localhost1/db1 |     0 | mysql |      0 |    0 | 1000 |       0 |          0 |        0 |       0 |            -1 |
| dn2  | localhost1/db2 |     0 | mysql |      0 |    0 | 1000 |       0 |          0 |        0 |       0 |            -1 |
| dn3  | localhost1/db3 |     0 | mysql |      0 |    0 | 1000 |       0 |          0 |        0 |       0 |            -1 |
+------+----------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
3 rows in set (0.01 sec)
NAME : dataNode 的名称
DATHOST : 对应 dataHost 属性的值,即数据主机
ACTIVE : 表示活跃连接数
IDLE : 表示闲置连接数
SIZE : 对应总连接数量

show @@heartbeat : 显示心跳状况
mysql> show @@heartbeat;
+--------+---------+-----------+------+---------+-------+--------+---------+--------------+---------------------+-------+
| NAME   | TYPE    | HOST      | PORT | RS_CODE | RETRY | STATUS | TIMEOUT | EXECUTE_TIME | LAST_ACTIVE_TIME    | STOP  |
+--------+---------+-----------+------+---------+-------+--------+---------+--------------+---------------------+-------+
| hostM  | mongodb | ci-server |   -1 |       1 |     0 | idle   |       0 | 1,1,1        | 2018-03-18 15:28:26 | false |
| hostM1 | mysql   | localhost | 3306 |      -1 |     0 | idle   |       0 | 0,0,0        | 2018-03-18 15:28:26 | false |
| hostS1 | mysql   | localhost | 3316 |      -1 |     0 | idle   |       0 | 0,0,0        | 2018-03-18 15:28:26 | false |
+--------+---------+-----------+------+---------+-------+--------+---------+--------------+---------------------+-------+
3 rows in set (0.00 sec)
RS_CODE : OK_STATUS =1 正常状态
                    ERROR_STATUS=-1 连接出错
                    TIMEOUT_STATUS=-2 连接超时
                    INIT_STATUS=0 初始化状态
若节点故障,会连续默认 5 个周期检测,心跳连续失败,就会变成-1,节点故障确认,然后可能发生切换

show @@version : 获取 MyCAT 的版本
mysql> show @@version;
+-----------------------------------------+
| VERSION                                 |
+-----------------------------------------+
| 5.6.29-mycat-1.6-RELEASE-20161028204710 |
+-----------------------------------------+
1 row in set (0.00 sec)

show @@connection : 获取 Mycat 的前端连接状态,即应用与 mycat 的连接
kill @@connection id,id,id : 用于杀掉连接
mysql> show @@connection;
+------------+------+------------+------+------------+------+--------+---------+--------+---------+---------------+-------------+------------+---------+------------+
| PROCESSOR  | ID   | HOST       | PORT | LOCAL_PORT | USER | SCHEMA | CHARSET | NET_IN | NET_OUT | ALIVE_TIME(S) | RECV_BUFFER | SEND_QUEUE | txlevel | autocommit |
+------------+------+------------+------+------------+------+--------+---------+--------+---------+---------------+-------------+------------+---------+------------+
| Processor0 |    1 | 172.17.0.2 | 9066 |      50148 | root | NULL   | utf8:33 |    818 |    7602 |          1471 |        4096 |          0 |         |            |
+------------+------+------------+------+------------+------+--------+---------+--------+---------+---------------+-------------+------------+---------+------------+
1 row in set (0.00 sec)

mysql> kill @@connection 1;
Query OK, 1 row affected (0.01 sec)

show @@backend : 查看后端连接状态

show @@cache : 查看 mycat 缓存
mysql> show @@cache;
+-------------------------------------+-------+------+--------+------+------+-------------+----------+
| CACHE                               | MAX   | CUR  | ACCESS | HIT  | PUT  | LAST_ACCESS | LAST_PUT |
+-------------------------------------+-------+------+--------+------+------+-------------+----------+
| ER_SQL2PARENTID                     |  1000 |    0 |      0 |    0 |    0 |           0 |        0 |
| SQLRouteCache                       | 10000 |    0 |      0 |    0 |    0 |           0 |        0 |
| TableID2DataNodeCache.TESTDB_ORDERS | 50000 |    0 |      0 |    0 |    0 |           0 |        0 |
+-------------------------------------+-------+------+--------+------+------+-------------+----------+
3 rows in set (0.00 sec)
SQLRouteCache : SQL 路由缓存
TableID2DataNodeCache : 缓存表主键与分片对应关系
ER_SQL2PARENTID : 缓存 ER 分片中子表与父表关系

show @@datasource : 查看数据源状态,如果配置了主从,或者多主可以切换
mysql> show @@datasource;
+----------+--------+-------+-----------+------+------+--------+------+------+---------+-----------+------------+
| DATANODE | NAME   | TYPE  | HOST      | PORT | W/R  | ACTIVE | IDLE | SIZE | EXECUTE | READ_LOAD | WRITE_LOAD |
+----------+--------+-------+-----------+------+------+--------+------+------+---------+-----------+------------+
| dn1      | hostM1 | mysql | localhost | 3306 | W    |      0 |    0 | 1000 |       0 |         0 |          0 |
| dn1      | hostS1 | mysql | localhost | 3316 | W    |      0 |    0 | 1000 |       0 |         0 |          0 |
| dn3      | hostM1 | mysql | localhost | 3306 | W    |      0 |    0 | 1000 |       0 |         0 |          0 |
| dn3      | hostS1 | mysql | localhost | 3316 | W    |      0 |    0 | 1000 |       0 |         0 |          0 |
| dn2      | hostM1 | mysql | localhost | 3306 | W    |      0 |    0 | 1000 |       0 |         0 |          0 |
| dn2      | hostS1 | mysql | localhost | 3316 | W    |      0 |    0 | 1000 |       0 |         0 |          0 |
+----------+--------+-------+-----------+------+------+--------+------+------+---------+-----------+------------+
6 rows in set (0.00 sec)

switch @@datasource name:inde : 切换数据源,name:schema 中配置的 dataHost 中 name
show @@sql : 显示8066 端口向 Mycat-Server 发送的 SQL 请求执行信息
show @@sql.slow : 将用户通过 8066 端口向 Mycat-Server 发送的请求执行 SQL 语句中超过慢 SQL 时间阈值的
show @@sql.sum : 向用户展示本地 8066 号端口上执行的 SQL 命令的统计信息数据

你可能感兴趣的:(MyCat)