主从切换过程具体步骤如下:
在从库上执行下面命令
STOP SLAVE IO_THREAD;
Command(s) completed successfully.
mysql> show processlist \G
*************************** 1. row ***************************
Id: 4
User: root
Host: localhost:60968
db: test
Command: Sleep
Time: 45
State:
Info: NULL
*************************** 2. row ***************************
Id: 6
User: system user
Host:
db: NULL
Command: Connect
Time: 3949
State: Slave has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
*************************** 3. row ***************************
Id: 7
User: root
Host: localhost:61007
db: NULL
Command: Query
Time: 0
State: NULL
Info: show processlist
3 rows in set (0.00 sec)
2、在从库上停止slave服务,然后执行reset master重置成为主库
STOP SLAVE;
RESET MASTER;
3、在从库B(192.168.1.102)上添加具有replication权限的用户repl,查询主库状态,命令如下
GRANT REPLICATION SLAVE ON *.*TO “repl”@”localhost” identified by “123”;
show master status;
4、修改主服务器的my.ini文件里的server-id为1,从服务器的server-id为2
5、在原来的主库(192.168.1.100)上配置复制参数
change master TO
master_host=”192.168.1.102″,
master_user=”repl”,
master_password=”123″,
master_port=3306,
master_log_file=”on.000004″,
master_log_pos=107;
6、在从库(192.168.1.100)上执行show slave status命令查看从库能否启动成功
START SLAVE;
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.102
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: on.000004
Read_Master_Log_Pos: 107
Relay_Log_File: joe-relay-bin.000006
Relay_Log_Pos: 246
Relay_Master_Log_File: on.000004
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 107
Relay_Log_Space: 436
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
到底问题出现在哪里呢
20
GRANT REPLICATION SLAVE ON *.*TO “repl”@”localhost” identified by “123”;
应该使用:
GRANT REPLICATION SLAVE ON *.*TO “repl”@”192.168.1.102” identified by “123”;
或
GRANT REPLICATION SLAVE ON *.*TO “repl”@”%” identified by “123”;
50
应该是这个问题
你看下在从库能不能够登陆到主库。