MYSQL read-write separation and sub-table
Target:
read-write separation
master+2×slave
Configure the master server
1 Create a replication account
create user cp_acct;
GRANT REPLICATION SLAVE ON *.* TO 'cp_acct'@'192.168.0.%' IDENTIFIED BY '123456';
2 Find the location of the mysql configuration file and modify it
mysql --help | grep my.cnf
1 server-id=1 //The unique identifier for the database service, generally set the end number of the server Ip for everyone
2 log-bin=master-bin
3 log-bin-index=master-bin.index
innodb_flush_log_at_trx_commit=1
sync_binlog=1
show master status;
Configure the slave server
1 [mysqld]
2 server-id=2
3 relay-log-index=slave-relay-bin.index
4 relay-log=slave-relay-bin
Connect to master:
master-bin.000001
change master to master_host='192.168.0.107',
master_port=3306,
master_user='cp_acct',
master_password='123456',
master_log_file='master-bin.000001',
master_log_pos=0;
slave start;
show slave status;
(2) Connect to Master
change master to master_host='192.168.0.104', //Master server Ip
master_port=3306,
master_user='repl',
master_password='mysql',
master_log_file='master-bin.000001', //log
master_log_pos generated by Master server =0;
(3) Start Slave
start slave;
----------
server-id=2
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
expire_logs_days = 10
max_binlog_size = 100M
# Replication slave
master-host="192.168.0.107"
master-user=cp_acct
master-password=123456
master-port=3306
master-connect-retry=60
replicate-do-db=usp
replicate-Ignore-db=information_schema
----------------
View status and debug