เวลาคำนวณ cal mysql
#mysqladmin -u root -p extended-status
--------------------------------
20080117 Fix Mysql replicate can't sync databases
##In slave DB server
#mysql -u root -p
mysql>slave stop;
mysql>reset slave;
##In Master DB server
#mysql -u root -p
mysql>show master status;
##Write down POSITION and LOG_FILE_NAME
#mysqldump --all-database --password=xxxx > dbsc00.db
#scp dbsc00.db
[email protected]:/home/golf/.
##IN slave DB server
#mysql -u root -p < dbsc00.db
mysql>change master to master_host='10.0.0.0',
master_user='slave_user',
master_password='xxx',
master_log_file='sc00-bin.000004', master_log_pos=136057;
mysql>slave start;
mysql>show slave status\G;
#It will show like this
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 207.131.5.120
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: sc00-bin.000004
Read_Master_Log_Pos: 143085
Relay_Log_File: mysql-relay-bin.000011
Relay_Log_Pos: 3088
Relay_Master_Log_File: sc00-bin.000004
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: 143085
Relay_Log_Space: 3088
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
1 row in set (0.00 sec)
ERROR:
No query specified
----------
ถ้าสมมติ slave start;
แล้ว slave_SQL_Running เป็น no แล้วมี error ขึ้น
Mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.152
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: adam-bin.000048
Read_Master_Log_Pos: 317714810
Relay_Log_File: db4-relay-bin.000001
Relay_Log_Pos: 290512385
Relay_Master_Log_File: adam-bin.000048
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1062
Last_Error: Error 'Duplicate entry 'dekq5g820avnfdmar5qi9dkhv3' for key 1' on query.
Default database:'session_sql'. Query: 'INSERT INTO sessi ons5 VALUES
('dekq5g820avnfdmar5qi9dkhv3', UNIX_TIMESTAMP(NOW()) + 18000, 'redir ect|i:1;')'
Skip_Counter:0
Exec_Master_Log_Pos: 290512419
Relay_Log_Space: 317714776
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: NULL
1 row in set (0.00 sec)
That means that by unavailablilty of master, slave was read, or unavailability of slave, master was
updated, so a query got two primary keys found for one entry which is a mess up.
So fixing it is by:
At slave:
Mysql> set global sql_slave_skip_counter=1;
Mysql> start slave;
Mysql> show slave status\G;