Debug School

rakesh kumar
rakesh kumar

Posted on • Edited on

How to setup trccaer gprs with mysql

Traccer gprs is by default available with H2 database


<!DOCTYPE properties SYSTEM 'http://java.sun.com/dtd/properties.dtd'>
<properties>

    <!-- Documentation: https://www.traccar.org/configuration-file/ -->

    <entry key='database.driver'>org.h2.Driver</entry>
    <entry key='database.url'>jdbc:h2:./data/database</entry>
    <entry key='database.user'>sa</entry>
    <entry key='database.password'></entry>
    <entry key='openid.clientId'>7</entry>
    <entry key='web.url'>https://traccar.motoshare.in</entry>
    <entry key='openid.force'>true</entry>
    <entry key='openid.clientSecret'>mBFTte6s64MRCrhs5N3Sd36Ch1POoPFXxDUgevXG</entry>
    <entry key='openid.issuerUrl'>https://demo.motoshare.in</entry>
    <entry key='openid.authUrl'>https://demo.motoshare.in/oauth/authorize</entry>
    <entry key='openid.tokenUrl'>https://demo.motoshare.in/oauth/token</entry>
    <entry key='openid.userInfoUrl'>https://demo.motoshare.in/api/user</entry>
    <entry key='logger.level'>all</entry>

</properties>

Enter fullscreen mode Exit fullscreen mode

Enter maria db or MySQL shell

mysql -u root -p
enter password: rakesh@123 then again enter password is available in Laravel project env 
Enter fullscreen mode Exit fullscreen mode

create database

CREATE DATABASE traccar CHARACTER SET utf8 COLLATE utf8_bin;
Enter fullscreen mode Exit fullscreen mode

Change configuration in configuration file

/opt/traccar/conf/traccar.xml
Enter fullscreen mode Exit fullscreen mode
  <entry key='database.driver'>com.mysql.cj.jdbc.Driver</entry>
    <entry key='database.url'>jdbc:mysql://localhost:3306/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=''</entry>
    <entry key='database.user'>root</entry>
Enter fullscreen mode Exit fullscreen mode

Restart traccar

sudo systemctl restart traccar
sudo systemctl status traccar
Enter fullscreen mode Exit fullscreen mode

output of sudo systemctl restart traccar

     Loaded: loaded (/etc/systemd/system/traccar.service; enabled; preset: enabled)
     Active: active (running) since Thu 2025-08-07 08:40:29 UTC; 8s ago
   Main PID: 349954 (java)
      Tasks: 27 (limit: 4600)
     Memory: 213.9M (peak: 214.3M)
        CPU: 16.408s
     CGroup: /system.slice/traccar.service
Enter fullscreen mode Exit fullscreen mode

note: it must be active

now add device from software

output

Trouble shoot

Error 500 or connection timed out

click track vehicle 2 or more times continous try
 because of memory or slowness issue
Enter fullscreen mode Exit fullscreen mode

go to logs directory

/opt/traccar/logs

vi tracker-server.log
Enter fullscreen mode Exit fullscreen mode

Invalid XML in traccar.xml

Invalid XML in traccar.xml
Even a small typo, incorrectly escaped special characters (like & in your JDBC URL), or invalid XML structure will cause status=1 failures.

Tip: Run this to check for errors:

xmllint conf/traccar.xml
Enter fullscreen mode Exit fullscreen mode

Fix any XML errors.

Special Characters in Password or URL
If your MySQL password or JDBC URL contains special characters, make sure they are valid within the XML and JDBC context. For instance, use & instead of & inside XML attributes, especially in your JDBC URL.

Example:

<entry key='database.url'>jdbc:mysql://localhost:3306/traccar?serverTimezone=UTC&amp;useSSL=false&amp;allowMultiQueries=true...</entry>
Enter fullscreen mode Exit fullscreen mode
mysql -u traccar -p -h localhost -P 3306
enter password   // in env file check
where traccar is database name
after run password u entered in maria db
Enter fullscreen mode Exit fullscreen mode

To use MySQL successfully you must:

Log in as root in MySQL and run the following:
Enter fullscreen mode Exit fullscreen mode
CREATE USER 'traccar'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON traccar.* TO 'traccar'@'localhost';
FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

Traccar is listening but you still get 503: Make sure Apache ProxyPass is correct and there are no local network blocks

error: when i run below command

sudo systemctl restart traccar
Enter fullscreen mode Exit fullscreen mode

ERROR: Main method error - Database is in a locked state. It could be due to early service termination on a previous launch. To unlock you can run this query: 'UPDATE DATABASECHANGELOGLOCK SET locked = 0'. Make sure the schema is up to date before unlocking the database. - DatabaseLockException (DatabaseModule:102 < <gener:-1 < *:-1 < ... < MainModule:139 < <gener:-1 < ...)
.

Solution:

mysql -h localhost -u root -p
USE traccar;
UPDATE DATABASECHANGELOGLOCK SET locked = 0;
ctrl d
sudo systemctl restart traccar
Enter fullscreen mode Exit fullscreen mode

Top comments (0)