mysql 主从库同步

时间:2023-03-10 04:22:39
mysql 主从库同步
#主库修改my.ini
[mysqld]
server-id=2
log-bin=mysql-bin
binlog-do-db=demo #从库修改my.ini
[mysqld]
server-id=3
replicate-do-db=demo --配置完成后重启主从库 #主库为从库添加用户
grant replication slave,reload,super on *.* to slave@14.23.88.110 identified by ''; show master status; 查询主机file/postin +------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 | 722 | demo | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)
#从库 检测是否能够连接上主库,保证主从通讯
stop slave; 关闭从机同步连接
change master to master_host='14.23.88.111',Master_Port=4569,master_user='slave',master_password='', master_log_file='mysql-bin.000004',master_log_pos=722;
start slave; --启动从机步连接
show slave status --查看状态 Waiting for master to send event 14.23.88.110 slave 4569 60 mysql-bin.000004 154 DELL-PC-relay-bin.000004 367 mysql-bin.000004 Yes Yes demo 0 0 154 623 None 0 No 0 No 0 0 2 ebd6ae04-6e14-11e8-b39c-444553544f53 C:\ProgramData\MySQL\MySQL Server 5.7\Data\master.info 0 Slave has read all relay log; waiting for more updates 86400 0