1,主库配置修改:server-id 不能和从库相同
my.cnf
[mysqld]
server-id=1
2,重启A机器的mysql
3,备份主库数据
./mysql/bin/mysqldump --defaults-extra-file=/home/mysql/backup/backup.cf --routines --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data=2 -A > ~/dump.sql
4,记录备份时主库MASTER_LOG_POS
head dump.sql -n80 | grep "MASTER_LOG_POS"
显示结果:-- CHANGE MASTER TO MASTER_LOG_FILE='binlog.000150', MASTER_LOG_POS=155;
5,拷贝备份dump数据
scp dump.sql 目前数据库@IP:/home******
6,从库数据还原
./mysql/bin/mysql -u root -p -S /home/promysql/mysql_3307/mysql.sock < dump.sql
7,主库同步用户创建
grant replication slave on *.* to 'abc'@'%' identified by '123456';
8,重启从库,在从库设置信息
change master to master_host='10.1.1.11', master_port=3306, master_user='abc',master_password='123456', master_log_file='mysql-bin.000002',master_log_pos=***;
网友评论