标签:主从 开启 sock creat word 主从复制 show 数据 from
1、模拟生产数据 create database prod; create table test1(id int,name varchar(20)); insert into test1 values(1,‘user1‘); insert into test1 values(2,‘user2‘); 2、备份主库 mysqldump -S /app/mysql/mysql.sock --single-transaction --master-data=2 --databases prod > /backup/hellodb_`date +%F`.sql insert into test1 values(3,‘user3‘); 3、从库导入数据 mysql -S /app/mysql/mysql.sock < /root/hellodb_2018-08-20.sql 查看导入的pos号,开启同步的时候需要用到 cat hellodb_2018-08-20.sql |grep MASTER_LOG_FILE -- CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000004‘, MASTER_LOG_POS=154; 4、在主库创建同步用户 CREATE USER ‘sync_user‘@‘192.168.0.99‘ IDENTIFIED BY ‘sync_user‘; GRANT REPLICATION SLAVE ON *.* TO ‘sync_user‘@‘192.168.0.99‘; flush privileges; 5、重启备库 删除/data/3306/auto.cnf rm /data/3306/auto.cnf mysqladmin -S /app/mysql/mysql.sock shutdown bin/mysqld_safe --basedir = /app/mysql --datadir=/data/3306 --pid-file=/app/mysql/mysql.pid & 5、从库开启同步,同步pos号请看第3步骤 CHANGE MASTER TO MASTER_HOST=‘192.168.0.98‘, MASTER_USER=‘sync_user‘, MASTER_PASSWORD=‘sync_user‘, MASTER_LOG_FILE=‘mysql-bin.000004‘, MASTER_LOG_POS=154; start slave; show slave status\G; Slave_IO_Running: Yes Slave_SQL_Running: Yes 上述输出表明同步成功。 6、数据对比 insert into test1 values(4,‘user4‘); select * from prod.test1;
标签:主从 开启 sock creat word 主从复制 show 数据 from
原文地址:https://www.cnblogs.com/houzhiqing/p/10302020.html