一、 配置 Master 主服务器
重启 MySQL 服务
server_id = 22
log-bin=master-bin
log-slave-updates=true
在 /etc/my.cnf 中修改或增加以下内容
service mysql restart
登录 AliSQL 程序,给服务器授权
mysql -u root -p
GRANT REPLICATION SLAVE ON *.* TO 'root'@'192.168.199.203' IDENTIFIED BY '1234abcd';
FLUSH PRIVILEGES;
show master status;
二、配置 Slave 从服务器
在 /etc/my.cnf 中修改或增加以下内容
server_id = 33
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
重启 MySQL 服务
service mysql restart
登录 AliSQL 程序,配置同步
mysql -u root -p
master_log_file 和 master_log_pos 根据主服务器“show master status;”给出的参数自行修改
启动同步
start slave;
查看 Slave 状态
show slave status\G;
确保以下两个值为 YES: Slave_IO_Running: Yes
Slave_SQL_Running: Yes
(补充)如报错,修改 auto.cnf 文件
Last_IO_Error: 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.
rm -rf /data/server/mysql/data/auto.cnf
service mysql restart
(补充)重启 Slave
mysql -u root -p stop slave;
start slave;
change master to
master_host='192.168.199.205',master_user='root',master_password='1234ab
cd',master_log_file='master-bin.000001',master_log_pos=120;
(补充)如果主服务器已经存在应用数据,则在进行主从复制时,需要锁表
主数据库进行锁表操作,不让数据再进行写入动作
FLUSH TABLES WITH READ LOCK;
解锁:UNLOCK TABLES;
来源:freebuf.com 2021-01-13 10:00:48 by: zcczcc
正文完