mycat管理浅述
Posted lovedb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mycat管理浅述相关的知识,希望对你有一定的参考价值。
1,mycat的端口分为服务端口及管理端口,可以通过如何方式进行定义
[root@mygirl conf]# pwd
/mycat_dir/mycat/conf
[root@mygirl conf]# more server.xml |grep -i port
<property name="serverPort">8066</property> <property name="managerPort">9066</property>
[root@mygirl conf]#
2,必须以9066管理端口才可以管理mycat
(注:mycat原生命令)
[root@mygirl ~]# /mysql56/bin/mysql -h10.0.0.5 -uroot -p -P9066 -DTESTDB
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (monitor)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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.
mysql>
3,mycat的管理命令
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.00 sec)
mysql>
4,mycat版本
mysql> show @@version;
+-----------------------------------------+
| VERSION |
+-----------------------------------------+
| 5.6.29-mycat-1.6-RELEASE-20161028204710 |
+-----------------------------------------+
1 row in set (0.00 sec)
5,显示mycat运行信息
mysql> show @@server;
+---------------+-------------+--------------+------------+---------------+---------------+---------+--------+
| UPTIME | USED_MEMORY | TOTAL_MEMORY | MAX_MEMORY | RELOAD_TIME | ROLLBACK_TIME | CHARSET | STATUS |
+---------------+-------------+--------------+------------+---------------+---------------+---------+--------+
| 10m 11s 358ms | 189262712 | 1037959168 | 4151836672 | 1517821968003 | -1 | utf8 | ON |
+---------------+-------------+--------------+------------+---------------+---------------+---------+--------+
1 row in set (0.00 sec)
6,显示mycat log的信息
mysql> show @@syslog limit=2;
+---------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| DATE | LOG |
+---------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2018-02-05 17:24:48 | .751 INFO [$_NIOConnector] (io.mycat.sqlengine.SQLJob.connectionError(SQLJob.java:114)) - can't get connection for sql :select user() |
| 2018-02-05 17:24:48 | .750 INFO [$_NIOConnector] (io.mycat.net.AbstractConnection.close(AbstractConnection.java:508)) - close connection,reason:java.net.ConnectException: Connection refused ,MySQLConnection [id=0, lastTime=1517822688741, user=root, schema=db1, old shema=db1, borrowed=false, fromSlaveDB=false, threadId=0, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=localhost, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] |
+---------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
7,显示mycat的参数配置
mysql> show @@sysparam;
+-------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PARAM_NAME | PARAM_VALUE | PARAM_DESCR |
+-------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| processors | 1 | 主要用于指定系统可用的线程数,默认值为Runtime.getRuntime().availableProcessors()方法返回的值。主要影响processorBufferPool、processorBufferLocalPercent、processorExecutor属性。NIOProcessor的个数也是由这个属性定义的,所以调优的时候可以适当的调高这个属性。 |
| processorBufferChunk | 4096B | 指定每次分配Socket Direct Buffer的大小,默认是4096个字节。这个属性也影响buffer pool的长度。 |
| processorBufferPool | 2097152B | 指定bufferPool计算 比例值。由于每次执行NIO读、写操作都需要使用到buffer,系统初始化的时候会建立一定长度的buffer池来加快读、写的效率,减少建立buffer的时间 |
| processorBufferLocalPercent | 100 | 就是用来控制分配这个pool的大小用的,但其也并不是一个准确的值,也是一个比例值。这个属性默认值为100。线程缓存百分比 = bufferLocalPercent / processors属性。 |
| processorExecutor | 4 | 主要用于指定NIOProcessor上共享的businessExecutor固定线程池大小。mycat在需要处理一些异步逻辑的时候会把任务提交到这个线程池中。新版本中这个连接池的使用频率不是很大了,可以设置一个较小的值。 |
| sequnceHandlerType | 本地文件方式 | 指定使用Mycat全局序列的类型。 |
| Mysql_packetHeaderSize | 4B | 指定Mysql协议中的报文头长度。默认4 |
| Mysql_maxPacketSize | 16M | 指定Mysql协议可以携带的数据最大长度。默认16M |
| Mysql_idleTimeout | 30分钟 | 指定连接的空闲超时时间。某连接在发起空闲检查下,发现距离上次使用超过了空闲时间,那么这个连接会被回收,就是被直接的关闭掉。默认30分钟 |
| Mysql_charset | utf8 | 连接的初始化字符集。默认为utf8 |
| Mysql_txIsolation | REPEATED_READ | 前端连接的初始化事务隔离级别,只在初始化的时候使用,后续会根据客户端传递过来的属性对后端数据库连接进行同步。默认为REPEATED_READ |
| Mysql_sqlExecuteTimeout | 300秒 | SQL执行超时的时间,Mycat会检查连接上最后一次执行SQL的时间,若超过这个时间则会直接关闭这连接。默认时间为300秒 |
| Mycat_processorCheckPeriod | 1秒 | 清理NIOProcessor上前后端空闲、超时和关闭连接的间隔时间。默认是1秒 |
| Mycat_dataNodeIdleCheckPeriod | 300秒 | 对后端连接进行空闲、超时检查的时间间隔,默认是300秒 |
| Mycat_dataNodeHeartbeatPeriod | 10秒 | 对后端所有读、写库发起心跳的间隔时间,默认是10秒 |
| Mycat_serverPort | 8066 | mycat的使用端口,默认值为8066 |
| Mycat_managerPort | 9066 | mycat的管理端口,默认值为9066 |
+-------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
18 rows in set (0.00 sec)
mysql>
8,显示近期执行过的sql
(注:从mycat执行)
mysql> select * from zxy;
Empty set (0.01 sec)
mysql> show @@connection.sql;
+------+----------+------+--------+---------------+--------------+-----------------------+
| ID | HOST | USER | SCHEMA | START_TIME | EXECUTE_TIME | SQL |
+------+----------+------+--------+---------------+--------------+-----------------------+
| 6 | 10.0.0.5 | root | TESTDB | 1517830945961 | 0 | show @@connection.sql |
| 7 | 10.0.0.5 | root | TESTDB | 1517830943522 | 22 | select * from zxy |
+------+----------+------+--------+---------------+--------------+-----------------------+
2 rows in set (0.00 sec)
9,显示数据源
(注:对应于schema.xml之datanode标签)
mysql> show @@datasource;
+----------+--------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+
| DATANODE | NAME | TYPE | HOST | PORT | W/R | ACTIVE | IDLE | SIZE | EXECUTE | READ_LOAD | WRITE_LOAD |
+----------+--------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+
| dn2 | hostM1 | mysql | localhost | 3306 | W | 0 | 10 | 1000 | 937 | 15 | 5 |
| dn2 | hostS1 | mysql | localhost | 3316 | W | 0 | 0 | 1000 | 0 | 0 | 0 |
| dn2 | hostS2 | mysql | 192.168.1.200 | 3306 | R | 0 | 0 | 1000 | 0 | 0 | 0 |
| dn3 | hostM1 | mysql | localhost | 3306 | W | 0 | 10 | 1000 | 937 | 15 | 5 |
| dn3 | hostS1 | mysql | localhost | 3316 | W | 0 | 0 | 1000 | 0 | 0 | 0 |
| dn3 | hostS2 | mysql | 192.168.1.200 | 3306 | R | 0 | 0 | 1000 | 0 | 0 | 0 |
| dn1 | hostM1 | mysql | localhost | 3306 | W | 0 | 10 | 1000 | 937 | 15 | 5 |
| dn1 | hostS1 | mysql | localhost | 3316 | W | 0 | 0 | 1000 | 0 | 0 | 0 |
| dn1 | hostS2 | mysql | 192.168.1.200 | 3306 | R | 0 | 0 | 1000 | 0 | 0 | 0 |
+----------+--------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+
9 rows in set (0.00 sec)
10,显示节点分片
mysql> show @@datanode;
+------+---------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
| NAME | DATHOST | INDEX | TYPE | ACTIVE | IDLE | SIZE | EXECUTE | TOTAL_TIME | MAX_TIME | MAX_SQL | RECOVERY_TIME |
+------+---------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
| dn1 | localhost/db1 | 0 | mysql | 0 | 8 | 1000 | 931 | 0 | 0 | 0 | -1 |
| dn2 | localhost/db2 | 0 | mysql | 0 | 1 | 1000 | 14 | 0 | 0 | 0 | -1 |
| dn3 | localhost/db3 | 0 | mysql | 0 | 1 | 1000 | 14 | 0 | 0 | 0 | -1 |
+------+---------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
3 rows in set (0.00 sec)
11,重载mycat配置
(注:server.xml,schema.xml,rules.xml变更)
mysql> reload @@config;
Query OK, 1 row affected (0.06 sec)
Reload config success
12,显示当前的逻辑库
mysql> show @@database;
+----------+
| DATABASE |
+----------+
| TESTDB |
+----------+
1 row in set (0.00 sec)
以上是关于mycat管理浅述的主要内容,如果未能解决你的问题,请参考以下文章