MySQL configuration fails due to XML escaping in traccar.xml (SAXParseException)

Nst Alarcon 2 months ago

Hello,

I noticed that the MySQL configuration example in the documentation uses a standard JDBC URL like:

jdbc:mysql://localhost/traccar?zeroDateTimeBehavior=round&serverTimezone=UTC&allowPublicKeyRetrieval=true...

However, when placing this inside traccar.xml, the server fails to start with:

SAXParseException (Config parsing error)

It seems the issue is that XML requires escaping special characters like "&", so the correct format should be:

&

instead of:

&

Also, for sessionVariables, using:

sql_mode=''

breaks XML and must be encoded as:

sql_mode=%27%27

So the working configuration becomes:

<entry key='database.url'>
jdbc:mysql://localhost/traccar?zeroDateTimeBehavior=round&amp;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=%27%27
</entry>

My question:
Would it be possible to update the documentation to reflect XML-safe configuration examples?

This could help avoid confusion for new installations.

Thanks!

Nst Alarcon 2 months ago
<entry key='database.driver'>com.mysql.cj.jdbc.Driver</entry>
<entry key='database.url'>jdbc:mysql://localhost/traccar?zeroDateTimeBehavior=round&amp;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=%27%27</entry>
<entry key='database.user'>[USER]</entry>
<entry key='database.password'>[PASSWORD]</entry>
Anton Tananaev 2 months ago

Fixed & escaping. It was broken in a recent website update. It used to be escaped correctly.

By the way sql_mode='' doesn't need to be escaped. It's valid XML as is.

Nst Alarcon 2 months ago

Hi Anton,
thanks for addressing this so quickly. We encountered this during a deployment and confirmed it was related to the documentation. Glad it's now fixed — it will save others quite some time.
Thanks again for your continued work on Traccar!

jkkostov 28 days ago

I follow all the described instructions for connecting to the mysql database, but the traccar server does not start.

Anton Tananaev 28 days ago

Are you getting the same error?

jkkostov 28 days ago

All is ok. There was no error. I added a port to the code and the service started. .... <entry key='database.url'>jdbc:mysql://localhost:3306/traccar?zeroDate ............