mycat官网地址
mkdir -p tools/mycat
cd tools/mycat/
wget http://dl.mycat.io/1.6.7.4/Mycat-server-1.6.7.4-release/Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz
tar -zxvf Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz
ll
将 mycat 放到“/usr/local/mycat/”目录下,你可以根据自己的需要选择合适的目录
cp -r mycat /usr/local/mycat
rm -rf mycat/
环境变量添加:
vim /etc/profile
添加
export MYCAT_HOME=/usr/local/mycat
export PATH=$PATH:$MYCAT_HOME/bin
使环境变量生效
source /etc/profile
测试是否生效:
echo $MYCAT_HOME
Linux 下部署安装 MySQL,默认不忽略表名大小写,需要手动到my.cnf(/etc/my.cnf)的[mysqld]区段下增加:
vim /etc/my.cnf
lower_case_table_names=1
使 MySQL 忽略表名大小写,否则使用 MyCAT 的时候会提示找不到表的错误!
[root@localhost mycat]# mycat start
Starting Mycat-server...
[root@localhost mycat]# mycat status
Mycat-server is running (5355).
[root@localhost mycat]# mycat stop
Stopping Mycat-server...
Stopped Mycat-server.
[root@localhost mycat]# mycat restart
Stopping Mycat-server...
Mycat-server was not running.
Starting Mycat-server...
查看mycat 用户名,密码
cat /usr/local/mycat/conf/server.xml
user
TESTDB
true
TESTDB
我们用mysql客户端或者mysql服务连接,ip为mycat主机ip,用户名root,密码123456,端口8066:
mysql -uroot -p123456 -P8066 -h192.168.169.138
再看目标数据库中数据:
192.168.169.138 mysql
发现只有db1的employee表中有数据,原因?
datanode=‘dn1,dn2’ rule=“sharding-by-intfile”
sharding-by-intfile是一种mycat一种分片规则,具体存放在rule.xml配置文件中:
PartitionByFileMap为mycat源码中的java类,注入了属性mapFile,值为partition-hash-int.txt,上述分片规则就是在这个txt文件中:
表示sharding_id值为10000时存放在第一个库,10010时存放在第二个库,规则可按实际业务需求手动配置。
mycat 有两个端口:8066数据端口 和9066管理端口
mysql -uroot -p123456 -P9066 -h192.168.169.138
通过 show @@help 可以查看所有命令
mysql> show @@help \G
*************************** 1. row ***************************
STATEMENT: show @@time.current
DESCRIPTION: Report current timestamp
*************************** 2. row ***************************
STATEMENT: show @@time.startup
DESCRIPTION: Report startup timestamp
*************************** 3. row ***************************
STATEMENT: show @@version
DESCRIPTION: Report Mycat Server version
*************************** 4. row ***************************
STATEMENT: show @@server
DESCRIPTION: Report server status
*************************** 5. row ***************************
STATEMENT: show @@threadpool
DESCRIPTION: Report threadPool status
*************************** 6. row ***************************
STATEMENT: show @@database
DESCRIPTION: Report databases
*************************** 7. row ***************************
STATEMENT: show @@datanode
DESCRIPTION: Report dataNodes
*************************** 8. row ***************************
STATEMENT: show @@datanode where schema = ?
DESCRIPTION: Report dataNodes
*************************** 9. row ***************************
STATEMENT: show @@datasource
DESCRIPTION: Report dataSources
*************************** 10. row ***************************
STATEMENT: show @@datasource where dataNode = ?
DESCRIPTION: Report dataSources
*************************** 11. row ***************************
STATEMENT: show @@datasource.synstatus
DESCRIPTION: Report datasource data synchronous
*************************** 12. row ***************************
STATEMENT: show @@datasource.syndetail where name=?
DESCRIPTION: Report datasource data synchronous detail
*************************** 13. row ***************************
STATEMENT: show @@datasource.cluster
DESCRIPTION: Report datasource galary cluster variables
*************************** 14. row ***************************
STATEMENT: show @@processor
DESCRIPTION: Report processor status
*************************** 15. row ***************************
STATEMENT: show @@command
DESCRIPTION: Report commands status
*************************** 16. row ***************************
STATEMENT: show @@connection
DESCRIPTION: Report connection status
*************************** 17. row ***************************
STATEMENT: show @@cache
DESCRIPTION: Report system cache usage
*************************** 18. row ***************************
STATEMENT: show @@backend
DESCRIPTION: Report backend connection status
*************************** 19. row ***************************
STATEMENT: show @@session
DESCRIPTION: Report front session details
*************************** 20. row ***************************
STATEMENT: show @@connection.sql
DESCRIPTION: Report connection sql
*************************** 21. row ***************************
STATEMENT: show @@sql.execute
DESCRIPTION: Report execute status
*************************** 22. row ***************************
STATEMENT: show @@sql.detail where id = ?
DESCRIPTION: Report execute detail status
*************************** 23. row ***************************
STATEMENT: show @@sql
DESCRIPTION: Report SQL list
*************************** 24. row ***************************
STATEMENT: show @@sql.high
DESCRIPTION: Report Hight Frequency SQL
*************************** 25. row ***************************
STATEMENT: show @@sql.slow
DESCRIPTION: Report slow SQL
*************************** 26. row ***************************
STATEMENT: show @@sql.resultset
DESCRIPTION: Report BIG RESULTSET SQL
*************************** 27. row ***************************
STATEMENT: show @@sql.sum
DESCRIPTION: Report User RW Stat
*************************** 28. row ***************************
STATEMENT: show @@sql.sum.user
DESCRIPTION: Report User RW Stat
*************************** 29. row ***************************
STATEMENT: show @@sql.sum.table
DESCRIPTION: Report Table RW Stat
*************************** 30. row ***************************
STATEMENT: show @@parser
DESCRIPTION: Report parser status
*************************** 31. row ***************************
STATEMENT: show @@router
DESCRIPTION: Report router status
*************************** 32. row ***************************
STATEMENT: show @@heartbeat
DESCRIPTION: Report heartbeat status
*************************** 33. row ***************************
STATEMENT: show @@heartbeat.detail where name=?
DESCRIPTION: Report heartbeat current detail
*************************** 34. row ***************************
STATEMENT: show @@slow where schema = ?
DESCRIPTION: Report schema slow sql
*************************** 35. row ***************************
STATEMENT: show @@slow where datanode = ?
DESCRIPTION: Report datanode slow sql
*************************** 36. row ***************************
STATEMENT: show @@sysparam
DESCRIPTION: Report system param
*************************** 37. row ***************************
STATEMENT: show @@syslog limit=?
DESCRIPTION: Report system mycat.log
*************************** 38. row ***************************
STATEMENT: show @@white
DESCRIPTION: show mycat white host
*************************** 39. row ***************************
STATEMENT: show @@white.set=?,?
DESCRIPTION: set mycat white host,[ip,user]
*************************** 40. row ***************************
STATEMENT: show @@directmemory=1 or 2
DESCRIPTION: show mycat direct memory usage
*************************** 41. row ***************************
STATEMENT: show @@check_global -SCHEMA= ? -TABLE=? -retry=? -interval=?
DESCRIPTION: check mycat global table consistency
*************************** 42. row ***************************
STATEMENT: switch @@datasource name:index
DESCRIPTION: Switch dataSource
*************************** 43. row ***************************
STATEMENT: kill @@connection id1,id2,...
DESCRIPTION: Kill the specified connections
*************************** 44. row ***************************
STATEMENT: stop @@heartbeat name:time
DESCRIPTION: Pause dataNode heartbeat
*************************** 45. row ***************************
STATEMENT: reload @@config
DESCRIPTION: Reload basic config from file
*************************** 46. row ***************************
STATEMENT: reload @@config_all
DESCRIPTION: Reload all config from file
*************************** 47. row ***************************
STATEMENT: reload @@route
DESCRIPTION: Reload route config from file
*************************** 48. row ***************************
STATEMENT: reload @@user
DESCRIPTION: Reload user config from file
*************************** 49. row ***************************
STATEMENT: reload @@sqlslow=
DESCRIPTION: Set Slow SQL Time(ms)
*************************** 50. row ***************************
STATEMENT: reload @@user_stat
DESCRIPTION: Reset show @@sql @@sql.sum @@sql.slow
*************************** 51. row ***************************
STATEMENT: rollback @@config
DESCRIPTION: Rollback all config from memory
*************************** 52. row ***************************
STATEMENT: rollback @@route
DESCRIPTION: Rollback route config from memory
*************************** 53. row ***************************
STATEMENT: rollback @@user
DESCRIPTION: Rollback user config from memory
*************************** 54. row ***************************
STATEMENT: reload @@sqlstat=open
DESCRIPTION: Open real-time sql stat analyzer
*************************** 55. row ***************************
STATEMENT: reload @@sqlstat=close
DESCRIPTION: Close real-time sql stat analyzer
*************************** 56. row ***************************
STATEMENT: offline
DESCRIPTION: Change MyCat status to OFF
*************************** 57. row ***************************
STATEMENT: online
DESCRIPTION: Change MyCat status to ON
*************************** 58. row ***************************
STATEMENT: clear @@slow where schema = ?
DESCRIPTION: Clear slow sql by schema
*************************** 59. row ***************************
STATEMENT: clear @@slow where datanode = ?
DESCRIPTION: Clear slow sql by datanode
59 rows in set (0.00 sec)
参考链接:https://blog.csdn.net/a281246240/article/details/83515077