MYSQL 读写分离及分表
目标:
读写分离
master+2×slave
配置master服务器
1 创建replication帐号
create user cp_acct;
GRANT REPLICATION SLAVE ON *.* TO 'cp_acct'@'192.168.0.%' IDENTIFIED BY '123456';
2 查找mysql配置文件位置,并修改
mysql --help | grep my.cnf
1 server-id=1 //给数据库服务的唯一标识,一般为大家设置服务器Ip的末尾号
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;
配置slave服务器
1 [mysqld]
2 server-id=2
3 relay-log-index=slave-relay-bin.index
4 relay-log=slave-relay-bin
连接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)连接Master
change master to master_host='192.168.0.104', //Master 服务器Ip
master_port=3306,
master_user='repl',
master_password='mysql',
master_log_file='master-bin.000001',//Master服务器产生的日志
master_log_pos=0;
(3)启动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
----------------
查看状态 及调试