Master
一、创建复制的用户
create user 'dba'@'192.168.%.%' identified by '123456';
grant replication slave on *.* to dba@'192.168.%.%';
Slave
mysql -u root -p < all.sqlchange master to master_host='192.168.55.133',
master_user='dba',
master_password='123456',
master_log_file='mysql-bin.000001',
master_log_pos=154;
start slave;
show slave status \G;
MySQL备份遇到的坑
mysqldump --single-transaction --master-data=2 --triggers --routines --all-databases -u root -p > all.sql
mysqldump --single-transaction --master-data=2 --triggers --routines --events --all-databases -u root -p > all.sql
当执行mysqldump命令后出现mysqldump: Error: Binlogging on server not active
在linux环境下,修改vi /etc/my.cnf文件,去掉mysqld下面log_bin的注释,将其改为
log_bin=mysql-bin
server_id=1
,输入命令systemctl restart mysqld重启MySQL。
GTID主从复制:
change master to
master_host='192.168.55.137',
master_port=3306,
master_user='dba',
master_password='123456',
master_auto_position=1;
关于从库的其他属性,特别重要
1、只读属性
read_only=on
super_read_only=on
2、slave的开启是否随着mysqld的启动而一起启动
skip_slave_start=on
3、log_slave_updates=on