mysql主从搭建过程

环境:vmware+centos7
先搭建一个mysql01节点,再克隆一台mysql02

在master(mysql01)上的操作:

在mysql01上创建用户:
更改密码策略为LOW

set global validate_password_policy=0;

更改密码长度

set global validate_password_length=0;
GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO slave@'%'IDENTIFIED BY '1234';
flush privileges;

修改配置,开启binlog

default-time-zone=’+8:00’
####### binlog 配置,确保可写入的日志文件 log-bin=/var/lib/mysql/logs/mysql-bin.log binlog_format=mixed#二进制日志的格式 binlog_do_db=dev#主从复制的数据库
binlog_ignore_db=mysql#不参与数从复制的数据库,例如mysql
binlog_checksum=none#mysql主从复制版本高
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

expire-logs-days=14 max-binlog-size=50M
#主机的标识 server-id=1

重启mysql

service mysqld restart

查看mysql的复制点

flush tables with read lock;
show master status;

mysql主从搭建过程_第1张图片

unlock tables;

在slave库(mysql02)上操作:

修改mysql配置:

default-time-zone=’+8:00’
#######binlog 配置,确保可写入的日志文件 log-bin=/var/lib/mysql/logs/mysql-bin.log binlog_format=mixed#二进制日志的格式 replicate_wild_do_table=dev.%
replicate_wild_ignore_table=mysql.%

expire-logs-days=14 max-binlog-size=50M
#主机的标识 server-id=2

stop slave;
change master to master_host='192.168.32.131',master_user='slave',master_password='1234',master_log_file='mysql-bin.000005',master_log_pos=150;
start slave;

出现错误:

Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.

原因与解决:
原因:mysql02是从mysql01完整拷贝的,需要修改一下auto.cnf中的server-uuid
解决:

mv /var/lib/mysql/auto.cnf /var/lib/mysql/auto.cnf.bak.20191125

重启mysql02,系统自动生成了新的server-uuid
重新执行

start slave;

成功!
mysql主从搭建过程_第2张图片

你可能感兴趣的:(mysql,mysql,主从)