MySQL error (1062,23000): Duplicate entry '0' for key 'PRIMARY' When i restore a mysql backup

Hi Everybody.

Im working with orthanc but always when i restore a mysql backup using the sames mysql versions and try to send new stydies, Orthanc log get this messages:

E0324 15:00:18.257801 PluginsManager.cpp:153] MySQL error (1062,23000): Duplicate entry ‘0’ for key ‘PRIMARY’
E0324 15:00:18.283982 StatelessDatabaseOperations.cpp:3335] EXCEPTION [Error with the database engine - ]
E0324 15:00:18.283982 PluginsManager.cpp:153] Cannot commit a non-existing transaction
E0324 15:00:18.285122 StoreScp.cpp:198] Exception while storing DICOM: Bad sequence of calls

My orthanc from i get the backups are running correctly but i cant get a good restore process.

i really appreciate your help.

Hi Danny,

Make sure the server where you restore the database does NOT have

sql_mode = NO_AUTO_VALUE_ON_ZERO

in its my.cnf.

This should make the trick.

Hi Cedric, first, thanks for your answer…

my.cnf is setted with => sql_mode=NO_ENGINE_SUBSTITUTION

And when i try to restore my backup, i put on disabled this: “Do not use AUTO_INCREMENT for zero values”.

But still im getting the same error in my orthanc log when i try to send a new study:

E0325 20:43:01.851782 PluginsManager.cpp:153] MySQL error (1062,23000): Duplicate entry ‘0’ for key ‘PRIMARY’
E0325 20:43:01.851782 StatelessDatabaseOperations.cpp:3335] EXCEPTION [Error with the database engine - ]
E0325 20:43:01.851782 PluginsManager.cpp:153] Cannot commit a non-existing transaction
E0325 20:43:01.856912 StoreScp.cpp:198] Exception while storing DICOM: Bad sequence of calls

I remain attentive to your recommendations, I really appreciate them enormously

Did you try copying the my.cnf file from main server to restore server?

Hi again Cedric. Again thanks for your help.

I replaced the mysql config file: my.cnf from the original server to my other server…and still i get the same error when i send a new study, even in the same original server, im getting the error:

E0326 11:47:34.508880 PluginsManager.cpp:153] MySQL error (1062,23000): Duplicate entry ‘0’ for key ‘PRIMARY’
E0326 11:47:34.511919 StatelessDatabaseOperations.cpp:3335] EXCEPTION [Error with the database engine - ]
E0326 11:47:34.511919 PluginsManager.cpp:153] Cannot commit a non-existing transaction
E0326 11:47:34.514330 StoreScp.cpp:198] Exception while storing DICOM: Bad sequence of calls

Cedric finally that was the solution, i’ve used --routines at the end of the mysqldump job…all is working fine…my restored mysql bd works fine.

Thanks for your help!!!