昊鼎王五:mysql配置主从关系时的语句master_log_pos的值到底填写什么?
关于MYSQL的主从配置,一般顺序是:
#先查看MASTER的状态:
show master status
#然后在从机器上面执行SQL语句,建立联系
模板语句是:
change master to master_host=‘IP’,
master_user=‘USER’,
master_password=‘PASSWORD’,
master_log_file=‘mysql-bin.000007’,
master_log_pos=2566;
此时,喜欢琢磨事的我发现,master_log_pos其实还有更多的赋值方法,就是直接如下:
change master to master_host=‘masterIP’,
master_user=‘hdww’,
master_password=‘haodingxxxxxxxxxx’,
master_log_file=‘mysql-bin.000007’,
master_log_pos=0;
看清楚,master_log_pos=0;就是这么简单,系统会自动匹配的,有图为证:
图中,Read_Master_Log_Pos: 2566已经显示出来了。
更重要的是,
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
这两项显示都是YES才为正常
如果出现no或者connecting,就要查看错误日志,根据错误原因来排除故障
将上图中完整的文字拷贝如下,以飨读者:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.x.203
Master_User: hdww
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 2566
Relay_Log_File: slave-relay.000002
Relay_Log_Pos: 2779
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
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: 2566
Relay_Log_Space: 2982
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
Master_UUID: f7837cb4-995a-11e8-bdf5-b8ca3a7c24df
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.03 sec)
mysql>
还有其他问题的可以在评论区留言或者如下联系方式扫码向我提问。