一 、下载jdbc 驱动
http://central.maven.org/maven2/mysql/mysql-connector-java/8.0.16/ ,下载之后将mycat/lib 文件夹下mysql-connector-java/5.1.35 删掉,上传mysql/mysql-connector-java/8.0.16/ 到mycat/lib 目录下。
再给jar包赋权限
[root@oracle-server lib]# chmod 777 mysql-connector-java-8.0.16.jar
二、修改schema.xml
<?xml version="1.0"?><mycat:schema xmlns:mycat=“http://io.mycat/”>
<schema name="TEST" checkSQLschema="true" sqlMaxLimit="100"> <!--(一定要把checkSQLschema改成true)--> <table name="tb_user" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" /> </schema> <dataNode name="dn1" dataHost="localhost1" database="db1" /> <dataNode name="dn2" dataHost="localhost1" database="db2" /> <dataNode name="dn3" dataHost="localhost1" database="db3" /> <!-- 修改dbDriver url --> <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="jdbc" switchType="1" slaveThreshold="100"> <heartbeat>show slave status</heartbeat> <writeHost host="hostM1" url="jdbc:mysql://192.168.1.28:3306?useSSL=false&serverTimezone=UTC" user="mysql账户" password="mysq密码" /> </dataHost> </mycat:schema>
修改server.xml
<!DOCTYPE mycat:server SYSTEM "server.dtd"> <mycat:server xmlns:mycat="http://io.mycat/"> <system> <property name="defaultSqlParser">druidparser</property> <property name="useHandshakeV10">1</property> <!--(这里记得修改)--> <property name="mutiNodeLimitType">1</property> <property name="charset">utf8</property> <property name="serverPort">8066</property> <property name="managerPort">9066</property> </system> <user name="mycat" defaultAccount="true"> <property name="password">mycat</property> <property name="schemas">TEST</property> </user> </mycat:server>
最后启动mycat :
mysql -umycat -pmycat -P8066 -h127.0.0.1
文章来源: https://blog.csdn.net/qq_42833774/article/details/97270154