固然了,要想解决问题得先有环境。
一主一从的配置流程:
主:先配置DNS解析,实验环境能够利用 /etc/hosts 解析
vim /etc/hosts
192.168.122.45 master1
192.168.122.46 master2
从机不用在配置,经过scp发送到从机
scp /etc/hosts master2:/etc
1 启动二进制日志,服务器ID,GTID
vim /etc/my.cnf
log-bin
server-id=1
gtid_mode=ON
enforce_gtid_consistency=1
重启mysql
systemctl restart mysqldmysql
date +%F
-mysql-all.sql还恢复手动同步数据
set sql_log_bin=0;sql
source /tmp/2018-3-20-mysql-full.sql 3.设置主服务器 mysql> change master to
master_host='master1',br/>master_user='rep',
master_password='QianFeng@123',
master_auto_position=1;vim
start slave; show slave status\G; 到这里没什么问题一主一从就部署完成了,若是有错误可借鉴如下方法排错,但愿能帮助到你们! 例: *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.60.159 Master_User: backup Master_Port: 3311 Connect_Retry: 60 Master_Log_File: mysql-bin.000012 Read_Master_Log_Pos: 274863854 Relay_Log_File: mysql-relay-bin.000007 Relay_Log_Pos: 2160037 Relay_Master_Log_File: mysql-bin.000012 Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1146
Last_Error: Error executing row event: 'Table 'panda.t' doesn't exist'
Skip_Counter: 0
Exec_Master_Log_Pos: 2159824
Relay_Log_Space: 274866725 服务器
错误缘由:主库删除的表在从库中不存在,致使从库在遇到删除不存在表的错误时没法继续同步。 解决方法:利用slave-skip-errors参数,跳过对于的1146错误(这个参数是一个只读的,须要在配置文件中修改,并重启从库) 一、在my.cnf的[mysqld]下面添加slave_skip_errors=1146
二、重启从库 systemctl restart mysqldide
三、在从库上启动同步
start slave;rest
四、去掉my.cnf中的slave_skip_errors=1146
五、重启从库 systemctl restart mysqld日志
六、启动从库复制
start slave;code
例: server
1. row
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.60.159
Master_User: backup
Master_Port: 3311
Connect_Retry: 60
Master_Log_File: mysql-bin.000012
Read_Master_Log_Pos: 274863854
Relay_Log_File: mysql-relay-bin.000007
Relay_Log_Pos: 2160037
Relay_Master_Log_File: mysql-bin.000012
Slave_IO_Running: No
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1146
Last_Error: Error executing row event: 'Table 'panda.t' doesn't exist'
Skip_Counter: 0
Exec_Master_Log_Pos: 2159824
Relay_Log_Space: 274866725 ip
错误缘由:主和从的UUID一致,需改动从机的UUID便可 解决方法: 1.在从机上 cd /var/lib/mysql ls 看到auto.cnf vim auto.cnf 随意改动一个数字便可 保存并退出 systemctl restart mysqld 2.进入Mysql start slave; 成功 好了,到这里就结束了,有错的地方望你们批评和建议!!!