0
点赞
收藏
分享

微信扫一扫

mysql主从复制配置

一、主库配置:

[mysqld]
server-id = 1
log-bin = mysql-bin
binlog_format = ROW

重启主数据库后用客户端登陆主库:

GRANT REPLICATION SLAVE ON *.* TO 'root'@'%';
flush privileges;

获取主库状态,主库执行  show master status;   记录file 和position的值

mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 |      120 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

二、从库配置

server-id = 2

重启从库数据库

配置从库连接主库并开始复制:
change master to master_host='主库的IP',master_port=3306,master_user='root',master_password='主库密码',master_log_file='mysql-bin.000001',master_log_pos=120;
start slave;

检查复制状态:在从库上执行 

SHOW SLAVE STATUS\G;

检查 Slave_IO_Running 和 Slave_SQL_Running 字段的值。如果这两个值均为 "Yes",则表示主从复制已成功配置。

如果同步失败,先stop slave,再看主库log_file和postion的值,重新配置从库连接主库,然后start slave即可。

举报

相关推荐

0 条评论