Mysql Connection issue

pascal8 years ago

Hello

I try to connect traccar 3.9 to Mysql on a test platform
(it is OK on a production one in 3.7)

I'm started from scratch (database empty) , it works with H2 database so the installation is OK.

When I configure :

<entry key='database.driver'>com.mysql.jdbc.Driver</entry> 
<entry key='database.url'>jdbc:mysql://localhost:3306/traccarOrig?allowMultiQueries=true&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&sessionVariables=sql_mode=''</entry>
<entry key='database.user'>traccar</entry> 
<entry key='database.password'>mypassword</entry>

I got this error with wrapper :

INFO|7585/0|Service traccar|16-12-10 12:05:03|Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

I did a small pph script to test the connection with the same parameters on the same server and it works

<?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'traccarOrig';
$dbuser = 'traccar';
$dbpass = 'mypasswd';
$dbhost = 'localhost';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
  $tblCnt++;
  #echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
  echo "There are no tables<br />\n";
} else {
  echo "There are $tblCnt tables<br />\n";
}

Any idea what could be wrong from traccar connection ?

Unknown8 years ago

Hi,

I didn't have any problems during the migration from H2 to MySQL.

My procedure (example):

  • unzip traccar

  • run traccar.run

  • install MySQL server (not mariaDB)

    $ mysql -u root -p
    > CREATE DATABASE TRACCAR;
    > CREATE USER 'traccardb'@'localhost' IDENTIFIED BY 'mypassword';
    > GRANT ALL PRIVILEGES ON TRACCAR.* TO 'traccerdb'@'localhost';
    > FLUSH PRIVILEGES;
    
  • Edit traccar.xml (https://www.traccar.org/mysql/)

    <entry key='database.driver'>com.mysql.jdbc.Driver</entry> 
    <entry key='database.url'>jdbc:mysql://localhost:3306/TRACCAR?allowMultiQueries=true&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&sessionVariables=sql_mode=''</entry>
    <entry key='database.user'>traccardb</entry> 
    <entry key='database.password'>mypassword</entry>
    
  • run /opt/traccar/bin/startDaemon.sh (Automatic creation of tables)

B.

Anton Tananaev8 years ago

@pascal, I would recommend to try any JDBC tool to connect. Possibly your MySQL doesn't accept network connections.

pascal8 years ago

I finally found the issue after some hours of research ...

the bind_adress of mysql was the ip address of the server in order to be able to access externally for some other databases.
so putting this ip address into traccar.xml instead of localhost solved the issue ...

(I don't understand how my php test was able to work in this condition ...)

Thanks for help

AlexS8 years ago

Hi,
Anton wrote:"– install MySQL server (not mariaDB)". Does traccar support MariaDB?

Thanks

Anton Tananaev8 years ago

Yes, it does.