08月25, 2017

mysql主从配置

my.cnf配置

[mysqld]
character-set-server=utf8mb4
thread_handling=pool-of-threads
thread_pool_max_threads=1000
thread_pool_idle_timeout=900
max_connections=3001
#在master增加配置
server-id=153
log_bin = mysql-bin
relay_log = /var/lib/mysql/mysql-relay-bin
log_slave_updates = 1
read_only =1

数据库设置

#分别在master和slave上创建用户
create user slave identified by 'slave#mysql123';
grant replication slave,replication client on *.* to 'slave'@'192.168.1.%' identified by 'slave#mysql123';
flush privileges;
# 停止slave
STOP SLAVE IO_THREAD FOR CHANNEL '';
# 查看slave状态
show slave status\G;
# 查看master状态,用于设置slave【File、Position】
show master status\G;
# 在slave设置master
change master to master_host='192.168.1.12',master_user='slave',master_password='slave#mysql123',master_log_file='File',master_log_pos=Position;
# 开启slave
start slave;

binlog内容查看

mysqlbinlog  -v --base64-output=DECODE-ROWS /home/log/mysql/bin-file.000448 | grep -A '20' 210812275

本文链接:https://blog.jnliok.com/post/mysql-master-slave.html

-- EOF --

Comments