本帖最后由 thepoy 于 2019-7-18 12:41 编辑
主机给从机添加授权:
[SQL] 纯文本查看 复制代码 GRANT REPLICATION SLAVE ON *.* TO 'user01'@'192.168.226.129' IDENTIFIED BY '123456';
刷新后:
[SQL] 纯文本查看 复制代码 show master status;
+-----------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-----------------+----------+--------------+------------------+
| mysqlbin.000004 | 858 | | mysql |
+-----------------+----------+--------------+------------------+
主机的二进制文件和serverid均已设置。
从机改slave:
[SQL] 纯文本查看 复制代码 CHANGE MASTER TO MASTER_HOST='192.168.0.104',
MASTER_USER='user01',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysqlbin.000004',MASTER_LOG_POS=858;
这样就报错了:
[SQL] 纯文本查看 复制代码 show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
省略n行
Last_IO_Error: error connecting to master 'user01@192.168.0.104:3306' - retry-time: 60 maximum-retries: 86400 message: Access denied for user 'user01'@'192.168.0.104' (using password: YES)
1 row in set (0.000 sec)
密码没错和pos正确,但无法连接。
然后想着添加一个账户,把把主机的授权ip变为任意ip:
[SQL] 纯文本查看 复制代码 GRANT REPLICATION SLAVE ON *.* TO 'user03'@'%' IDENTIFIED BY '123456';
把file和pos的更新写入slave后成功:
[SQL] 纯文本查看 复制代码 show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.104
Master_User: user03
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqlbin.000004
Read_Master_Log_Pos: 858
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 554
Relay_Master_Log_File: mysqlbin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
同一个网络环境下,用的都是内网ip,主机和从机的ip能互相ping能,为什么会报这种错呢?
|