Mysql多实例主从复制

Mysql多实例主从复制

主库:

1.创建主从复制用户
mysql> grant file on *.* to 'test'@'127.0.0.1' identified by '123';

mysql> grant replication slave on *.* to test@'127.0.0.1' identified by '123';
2.查看binlog名和位置
show master status;
+------------------+----------+
| File             | Position |
+------------------+----------+
| mysql-bin.000003 |      661 |
+------------------+----------+

从库:

1.告诉从库,我的主库是谁?主库的主从复制用户是谁?主从复制用户的密码?端口?binlog名?binlog位置
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> change master to
    -> master_host='127.0.0.1',
    -> master_user='test',
    -> master_password='123',
    -> master_log_file='mysql-bin.000003',
    -> master_log_pos=661,
    -> master_port=3309;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
2.开启主从复制(开启IO线程和 SQL线程)
开启从库
> start slave;


3.检查主从复制状态信息:

> show slave status\G

下面的两个必须都为yes才是成功。

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

如果IO线程是no

数据库主从问题从库上Slave_IO_Running: Connecting
在做mysql主从同步的时候有时候发现在从库上Slave_IO_Running: Connecting

1.网络不通 #互ping机器ip,无丢包率正常访问,排除

2.密码不对 #MySQL重新授权远程用户登陆账号,重新设置密码,排除

3.pos不正确 #主服务器,登陆数据库重新查看起始偏移量show master status,排除

4.ID问题 #server-id要不同

1.检测网络:
[root@db01 data]# ping 127.0.0.1

2.检测端口:
[root@db01 data]# telnet 127.0.0.1 3309

3.检测账号,密码:
mysql -utest -p123 -h127.0.0.1 -P 3309

猜你喜欢

转载自www.cnblogs.com/longren/p/11166425.html
今日推荐