sql_require_primary_key error when switching to Mysql database

Hagenes2 years ago

Hi all,

I'm attempting to change the database to mysql. When restarting the traccar service it runs for a few seconds (assuming running the DB migrations) and then fails with the below logs. sql_require_primary_key seems to be the culprit. I am reaching out because I did not find anything on this forum or Google.

Also below is my traccar.xml. As you can see I am using DigitalOcean managed MySQL 8 database.

It does seem to connect as I see 1 table created DATABASECHANGELOGLOCK

Please let me know if there is something on traccar side to install or tweak or something on the system I need.

2023-03-02 16:58:44  INFO: Operating system name: Linux version: 5.15.0-50-generic architecture: amd64
2023-03-02 16:58:44  INFO: Java runtime name: OpenJDK 64-Bit Server VM vendor: Eclipse Adoptium version: 17.0.6+10
2023-03-02 16:58:44  INFO: Memory limit heap: 235mb non-heap: 0mb
2023-03-02 16:58:44  INFO: Character encoding: UTF-8 charset: UTF-8
2023-03-02 16:58:44  INFO: Version: 5.6
2023-03-02 16:58:44  INFO: Starting server...
2023-03-02 16:58:45  INFO: HikariPool-1 - Starting...
2023-03-02 16:58:46  INFO: HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@3c818ac4
2023-03-02 16:58:46  INFO: HikariPool-1 - Start completed.
2023-03-02 16:58:47  INFO: Clearing database change log checksums
2023-03-02 16:58:48  INFO: Successfully acquired change log lock
2023-03-02 16:58:48  INFO: Creating database history table with name: defaultdb.DATABASECHANGELOG
2023-03-02 16:58:48  INFO: Successfully released change log lock
2023-03-02 16:58:48 ERROR: Main method error - Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting. - SQLException (... < DatabaseModule:95 < <gener:-1 < *:-1 < ... < Main:126 < ...)
    <entry key='database.driver'>com.mysql.cj.jdbc.Driver</entry>
    <entry key='database.url'>jdbc:mysql://MYHOSTHERE.ondigitalocean.com:25060/defaultdb?serverTimezone=UTC&amp;allowPublicKeyRetrieval=true&amp;useSSL=false&amp;allowMultiQueries=true&amp;autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF-8&amp;sessionVariables=sql_mode=''</entry>
    <entry key='database.user'>MYUSERNAME</entry>
    <entry key='database.password'>MYPASSWORD</entry>
Anton Tananaev2 years ago

We do use tables without primary keys, if that's what you're asking.

Track-trace2 years ago