Fixing encoding for MySQL

Anton Tananaev4 years ago

If you have errors like this:

WARN: Incorrect string value: '\xEF\xBF\xBD\xEF\xBF\xBD...' for column 'name' at row 1 - SQLException (... < QueryBuilder.java: ...)

It means that MySQL encoding is not correct. Traccar is expecting database to accept UTF strings.

To change encoding on existing database you can use following queries:

  1. Change default encoding on the whole database:
ALTER DATABASE traccar CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  1. For each existing table run following query:
ALTER TABLE tc_users CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

You can get a list of tables in the database using following query:

SHOW TABLES;