Wednesday, September 19, 2018

.::: How to Simple Troubleshooting Error 'Duplicate entry '9999707' on slave/master MySQL/MariaDB include repair table database:::.

1. Get Error on replication/mirroring MySQL/MariaDB
 Last_Error: Error 'Duplicate entry '9999707' for key 'PRIMARY'' on query. Default database: 'teguht'. Query: 'INSERT INTO sessions (session_id, data_key, data_value, serialized) VALUES ('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastScreenOverview','Action=AgentFAQExplorer;SortBy=FAQID;CategoryID=0;Nav=;OrderBy=Down;StartHit=1','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastScreenView','Action=AgentFAQExplorer;SortBy=FAQID;CategoryID=0;Nav=;OrderBy=Down;StartHit=1','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastViewedCategory','0','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','UserFAQOverviewAgentFAQExplorer','Small','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','UserLastRequest','1537333985','0')

mysql> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.10.20
                  Master_User: replica
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000009
          Read_Master_Log_Pos: 74848761
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 24612
        Relay_Master_Log_File: mysql-bin.000009
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: teguht
          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 '9999707' for key 'PRIMARY'' on query. Default database: 'teguht'. Query: 'INSERT INTO sessions (session_id, data_key, data_value, serialized) VALUES ('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastScreenOverview','Action=AgentFAQExplorer;SortBy=FAQID;CategoryID=0;Nav=;OrderBy=Down;StartHit=1','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastScreenView','Action=AgentFAQExplorer;SortBy=FAQID;CategoryID=0;Nav=;OrderBy=Down;StartHit=1','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastViewedCategory','0','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','UserFAQOverviewAgentFAQExplorer','Small','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','UserLastRequest','1537333985','0')'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 74805390
              Relay_Log_Space: 68138
              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
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 1062
               Last_SQL_Error: Error 'Duplicate entry '9999707' for key 'PRIMARY'' on query. Default database: 'teguht'. Query: 'INSERT INTO sessions (session_id, data_key, data_value, serialized) VALUES ('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastScreenOverview','Action=AgentFAQExplorer;SortBy=FAQID;CategoryID=0;Nav=;OrderBy=Down;StartHit=1','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastScreenView','Action=AgentFAQExplorer;SortBy=FAQID;CategoryID=0;Nav=;OrderBy=Down;StartHit=1','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','LastViewedCategory','0','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','UserFAQOverviewAgentFAQExplorer','Small','0'),('E6iNeYTAMo4FBl2gpoicy0kWVqYfTygv','UserLastRequest','1537333985','0')'
1 row in set (0.00 sec)

ERROR:
No query specified

mysql>

2. Additional my.ini or my.cnf
slave-skip-error=1062


[root@teguht02 ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
server_id=2
replicate-do-db=teguht
#bind-address=10.10.10.20
log-bin      = mysql-bin
binlog_do_db = teguht
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin

slave-skip-error=1062

[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@teguht01 ~]#

3. Restart MySQL/MariaDB
# service mysqld restart

4. Before set master to master or master to slave, stop slave and reset slave and reset master

mysql> stop slave;
mysql> reset slave
mysql> reset master

5. set master to master or master to slave base on http://teguhth.blogspot.com/2018/08/how-to-redundant-set-master-to-master.html

6. check master status
mysql> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.10.20
                  Master_User: replica
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 1140288
               Relay_Log_File: mysql-relay-bin.000006
                Relay_Log_Pos: 1140433
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: teguht
          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: 1140288
              Relay_Log_Space: 1140733
              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:
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> 

7. or seting global skip on slave

STOP SLAVE; 
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 2;
START SLAVE;

8. Repair all table database
 mysqlcheck -u root -p --auto-repair --check --all-databases

9. repair a table database 
use databasename
repair table tablename

detail repair table
https://teguhth.blogspot.com/2019/08/repair-table-database-mysql-mariadb.html


No comments:

Post a Comment

Popular Posts