mysql 主从复制

2019-12-20  本文已影响0人  luncene_e110

1.master mysql root用户上创建用于同步的账号

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%'IDENTIFIED BY '123456';

flush privileges;

2.修改配置文件,开启二进制日志

server_id=1

log-bin=master-mysql-bin

binlog_ignore_db=mysql

binlog_cache_size=1M

binlog_format=mixed

3.重启master主机

4.修改slave数据库配置文件

server_id=2

log-bin=slave-mysql-bin

binlog_ignore_db=mysql

binlog_cache_size=1M

binlog_format=mixed

relay_log=mysql-relay-bin

log_slave_updates=1

read_only=1

5.重启slave

6.在slave上执行命令

change master to master_host='172.28.8.30',

master_user='repl',

master_password='123456',

master_port=3306,

master_log_file='master-mysql-bin.000001',

master_log_pos=10362,

master_connect_retry=30;

7.启动slave

start slave;

对已有数据做的数据库做主从:

1.使用如下锁表命令

flush tables with read lock;

2.导出master的数据

mysqldump -h 172.28.8.30 -u root -p  coolPay>coolPay.sql

3.拷贝数据库脚本到目标主机

scp coolPay.sql ctf@172.28.8.31:/home/ctf

4.slave机器上导入数据

mysql -h 172.28.8.31 -u root -p coolPay</home/ctf/coolPay.sql

5.查看master上的binlog位置 ,然后释放锁表(unlock tables;)然后执行上面的第6步和第7步

参考链接:

https://www.cnblogs.com/jefflee168/p/7407328.html

https://blog.csdn.net/Bin594505536/article/details/79115506

https://blog.csdn.net/zhilonng/article/details/51754390

上一篇下一篇

猜你喜欢

热点阅读