You need to have the following environment
1 mysql master copy from
2 jdk installation and configuration environment variables
Please refer to mysql master-slave replication
Refer to install mysql in linux
The following is my demo Reference:
192.168.142.26 master- mysql includes a main condition from the master copy from
192.168.142.25 slave- mysql includes a master from the master copy condition from
192.168.142.27 slave- mysql includes a master-slave from the master copy condition
192.168.142.28 mycat install mysql
The compressed Mycat-server-1.6.7.3-release-20190828135747-linux.tar.gz copied to the / usr / local unzipped
tar -zvxf Mycat-server-1.6.7.3-release-20190828135747-linux.tar.gz
Check whether the installation and configuration environment variable jdk
jps # or java -version
Please refer to linux (centOS7) installed jdk configuration environment variable
schema.xml file modifications myact / conf follows
<Schema name = "the TESTDB" checkSQLschema = "to true" sqlMaxLimit = "100" Datanode = "DNl"> </ Schema> <Datanode name = "DNl" DataHost = "host1" Database = "Test" /> <! - writeType = "1", all the write operations are arranged to send a random writeHost . 3 based on the switching mechanism of the MySQL galary cluster (cluster adapted) (1.4.1) -> <DataHost name = "host1" maxCon = "1000" Mincon = "10" = Balance ". 3" writeType = ". 1" dbType = "MySQL" dbDriver = "Native" switchType = ". 1" slaveThreshold = "100"> <-! check the heartbeat -> <heartbeat> SELECT User ( ) </ Heartbeat> <-! wrote node configuration -> <Host = writeHost "hostM1" url = "192.168.142.26:3306" the User = "root" password = "123456"> <-! account password from the address database and the database -> <readHost host="hostM2" url="192.168.142.25:3306" user="root" password="123456" /> <readHost host="hostM3" url="192.168.142.27:3306" user="root" password="123456" /> </writeHost> </dataHost>
service.xml file modifications myact / conf follows
<user name="test" defaultAccount="true"> <property name="password">123456</property> <!-- 与schema中的名称保持一致 --> <property name="schemas">TESTDB</property> </user>
rule.xml file modifications myact / conf follows
<tableRule name="rule1"> <rule> <!-- 主键 --> <columns>id</columns> <!-- 分片规则 --> <algorithm>func1</algorithm> </rule> </tableRule> <function name="func1" class="io.mycat.route.function.PartitionByLong"> <!-- 分片数量 --> <property name="partitionCount">8</property> <!-- 分片最大长度 --> <property name="partitionLength">128</property> </function>
修改mycat下的log4j2.xml
<asyncRoot level="debug" includeLocation="true">
启动myacat
cd /usr/local/mycat/bin ./mycat start #启动mycat
./mycat status #查看启动状态
登录mycat
mysql -h 192.168.142.28 -P8066 -u test -p
use TESTDB; create table user(id int primary key,name varchar(100)); insert into user(id,name) values(1,'xiaoming'); select @@hostname; select * from test.user;
查看日志
192.168.142.26 只有写节点进行了写操作
192.168.142.25 192.168.142.27 读节点进行读取数据
简单的mycat环境搭建ok!如果出现无法连接的现象,记得关闭防火墙!
如有问题,欢迎交流