MyCat详细介绍,请参考https://www.biaodianfu.com/mycat.html
9066管理端口,请参考https://www.cnblogs.com/parryyang/p/5606071.html
1.创建mycat用户
useradd mycat passwd mycat
2.下载安装包、解压并赋权
wget http://dl.mycat.io/1.6.6.1/Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz tar -xzvf Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz -C /usr/local chown -R mycat:mycat /usr/local/mycat
3.配置环境变量
vi /etc/profile 增加 ## jdk env JAVA_HOME=/usr/java/jdk1.8.0_192 CLASSPATH=$JAVA_HOME/lib/ PATH=$PATH:$JAVA_HOME/bin export PATH JAVA_HOME CLASSPATH ## mycat env export MYCAT_HOME=/usr/local/mycat export PATH=$PATH:$MYCAT_HOME/bin source /etc/profile
4.配置server.xml
vi /usr/local/mycat/conf/server.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mycat:server SYSTEM "server.dtd"> <mycat:server xmlns:mycat="http://io.mycat/"> <system> <!-- <property name="processors">32</property> <property name="processorExecutor">32</property> <property name="bindIp">0.0.0.0</property> <property name="frontWriteQueueSize">4096</property> <property name="idleTimeout">300000</property> <property name="mutiNodePatchSize">100</property> --> <property name="defaultSqlParser">druidparser</property> <property name="mutiNodeLimitType">1</property> <property name="serverPort">8066</property> <property name="managerPort">9066</property> </system> <!-- 任意设置登陆 mycat 的用户名,密码,数据库 --> <user name="test"> <property name="password">test</property> <property name="schemas">TESTDB</property> </user> <user name="user"> <property name="password">user</property> <property name="schemas">TESTDB</property> <property name="readOnly">true</property> </user> <!-- <quarantine> <whitehost> <host host="127.0.0.1" user="mycat"/> <host host="127.0.0.2" user="mycat"/> </whitehost> <blacklist check="false"></blacklist> </quarantine> --> </mycat:server>
5.配置schema.xml
vi /usr/local/mycat/conf/schema.xml
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"> <!-- 这里不配置,代表所有的表分片到dn1节点--> </schema> <dataNode name="dn1" dataHost="dataHost01" database="test" /> <dataHost name="dataHost01" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <writeHost host="mysql_b1" url="192.168.0.242:3306" user="root" password="abc123"> <!-- can have multi read hosts --> <readHost host="mysql_b2" url="192.168.0.240:3306" user="root" password="abc123" /> </writeHost> </dataHost> </mycat:schema>
6.启动Mycat
mycat start
7.查看mycat启动日志
[root@mycat-server2 data]# mycat console
Running Mycat-server...
Mycat-server is already running.
8.连接MyCat
连接管理端口:
[root@mycat-server2 data]# mysql -h192.168.0.252 -P9066 -utest -ptest 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 21 Server version: 5.6.29-mycat-1.6.6.1-release-20181031195535 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> 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 | | show @@check_global -SCHEMA= ? -TABLE=? -retry=? -interval=? | check mycat global table consistency | | 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 | +--------------------------------------------------------------+--------------------------------------------+ 59 rows in set (0.01 sec) # 查看所有的逻辑数据库: mysql> show @@database; +----------+ | DATABASE | +----------+ | TESTDB | +----------+ 1 row in set (0.00 sec) # 查看所有的数据节点: mysql> show @@datanode; Empty set (0.00 sec) mysql> show @@datasource; +----------+----------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+ | DATANODE | NAME | TYPE | HOST | PORT | W/R | ACTIVE | IDLE | SIZE | EXECUTE | READ_LOAD | WRITE_LOAD | +----------+----------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+ | dn1 | mysql_b1 | mysql | 192.168.0.242 | 3306 | W | 0 | 10 | 1000 | 6215 | 0 | 2 | | dn1 | mysql_b2 | mysql | 192.168.0.240 | 3306 | R | 0 | 9 | 1000 | 6299 | 84 | 0 | +----------+----------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+ 2 rows in set (0.00 sec) mysql> quit Bye
连接数据操作端口:
[root@mycat-server2 data]# mysql -h192.168.0.252 -P8066 -utest -ptest 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 22 Server version: 5.6.29-mycat-1.6.6.1-release-20181031195535 MyCat Server (OpenCloudDB) 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> show databases; +----------+ | DATABASE | +----------+ | TESTDB | +----------+ 1 row in set (0.00 sec) # 使用指定的逻辑数据库: mysql> use TESTDB; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed # 查看所有的数据表: mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | member | | t01 | | t02 | | t03 | +----------------+ 4 rows in set (0.03 sec)
参数说明:
-h 后面是主机,即当前 mycat 安装的主机地址,本地可用 127.0.0.1 远程需要远程 ip;
-u Mycat server.xml 中配置的逻辑库用户;
-p Mycat server.xml 中配置的逻辑库密码;
-P 后面是端口 默认 9066,注意 P 是大写;
-d Mycat server.xml 中配置的逻辑库。
9.MyCat操作命令:
启动MyCat: mycat start;
停止MyCat: mycat stop;
前台运行: mycat console;
重启服务: mycat restart;
暂停: mycat pause;
查看启动状态: mycat status;
10.修改log4j的配置
为了让信息启动时更好定位,需要将conf/log4j2.xml的文件修改为debug级别。
附:其他问题
MySQL8.0的客户端连不上Mycat?
解决方案:使用mysql5的客户端可以正常访问,待详细分析