mycat读写分离

mycat读写分离


一、安装mycat

1
2
3
4
5
6
7
8
9
10
11
tar xf Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz  -C /usr/src/

#环境变量/usr/src/mycat/bin
#服务器配置
10.1.0.18:3306 #主库
10.1.0.18:3307 #从库
10.1.0.17:3306 #mycat

#安装java
yum -y install java

二、创建mycat连接mysql账号

1
2
3
4
5
6
CREATE USER 'admin'@'%' IDENTIFIED BY '123456@Root';

GRANT ALL PRIVILEGES ON db1.* TO 'admin'@'%';
FLUSH PRIVILEGES;

ALTER USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY '123456@Root';

三、修改mycat配置

1
2
3
4
5
6
7
8
9
10
11
12
13
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
</schema>
<dataNode name="dn1" dataHost="10.1.0.18" database="db1" />
<dataHost name="10.1.0.18" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="host1" url="10.1.0.18:3306" user="admin"
password="123456@Root">
<readHost host="host2" url="10.1.0.18:3307" user="admin" password="123456@Root" />
</writeHost>
</dataHost>
</mycat:schema>