Mysql on Raspberry installation

Belldandy 2 years ago

Gentlemen, good evening.

I'm tryng to install Traccar to a raspberry (Raspberry Pi Zero 2 W). It's a fresh install and so far i just have to track 5 devices for my family.
I'm a total newbie on linux, but using tutorials i managed to have it up and running on another raspberry.

I wanted to move to sql as everyone suggests because on the other raspberry the default database crashes every sometimes (3 months or so). I found that deleting the databases with a rm * and restarting fro scratch works, but i would love to be more stable.

On the new one i installed maria-db and i think i also managed to create a user to the db for traccar. (it's in the user list table)

(from my terminal : )

MariaDB [(none)]> SELECT User, Db, Host from mysql.db;
+---------+---------+-----------+
| User    | Db      | Host      |
+---------+---------+-----------+
| root    | traccar | localhost |
| traccar | traccar | localhost |
+---------+---------+-----------+

I have read the article https://www.traccar.org/forums/topic/migration-from-h2-to-mysql/ , but it think is not what i need because mine is a fresh install and i do not need to migrate an existing database.

I have tried to follow istructions to replace h2 to mysql contained in https://www.traccar.org/mysql/ to let traccar use the mariadb instead of h2 , but when i launch it it does not end well (there are like 2 pages of errors, which i omit for convenience in this initial post).
It seems however that is due to database connection.

Again, from my terminal.

luca@zero-traccar:/opt/traccar $ sudo java -jar tracker-server.jar conf/traccar.xml
Exception in thread "main" java.lang.RuntimeException: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) [Guice/ErrorInCustomProvider]: HikariPool$PoolInitializationException: Failed to initialize pool: Could not create connection to database server.
***

Is there some good soul around whom managed to start from a fresh install for OS, DB and traccar itself and that is willing to share a step-by-step path for a newbie?

thank you in advance.
good evening everyone.
E.

Anton Tananaev 2 years ago

The error tells us that either the configuration is incorrect or the database is not accepting connections.

Belldandy 2 years ago

Good evening, Anton and thank you for the reply (and for the whole software ).
I agree, I have the feeling that mariadb don't accept connections (I copied traccar config changes from the instructions ,so problems must be somewhere else).
But from here, I'm lost.
I don't have enough knowledge to debug the issue.

I know that it's always bad to ask for a ready meal, but I hope someone might share a step by step guide inclusive of database part to start again from zero and hopefully have it working.

That's the reason for my post. I hope you understand me.

Have a nice evening .
E.

Anton Tananaev 2 years ago

Have you tried the MariaDB command line to see if you can connect? Make sure you try network connection.

Belldandy 2 years ago

If you mean launch console , I did and seems alive. Connecting to port from another device in the same subnet fails. I will try to to study about connect to dB and come back to you, I will do in weekend.
Have a nice day :)

Anton Tananaev 2 years ago

Have you allowed network connections in the DB config?

Belldandy 2 years ago

I have found a guide to edit a config file to allow connections not only from localhost ( sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf and commenting the bind to localhost address).
I installed dbeaver on a normal pc and even so i get the error that pc can't connect to the db .
Maybe i screwed up something, i'm just now burning the raspi SD and i will restart from scratch. i hope to finish the reinstall before night and work on it next weekend....
btw,
I found a guide to install mariadb, https://hackernoon.com/setting-up-a-dedicated-database-server-on-raspberry-pi
Do you agree with procedures or you have something better / idiot proof to suggest?
thanks.

Anton Tananaev 2 years ago

The article is completely unrelated to your problem.

Belldandy 2 years ago

well, in any case im starting from scratch. im installing mariadb right now ( sudo apt install mariadb-server ) and create an user, then try to connect with the database from PC using dbeaver. If im successful i will proceed with dowloading traccar, changing the configuration file to use sql. everithing should go smooth.
If you have instruction, suggestion, something i really would be grateful for it. as stated in the very beginning of this thread, im not a power user and im basically clueless on everything im doing. be compassionate.
e.

Anton Tananaev 2 years ago

I would just recommend connecting locally using command line mariadb or mysql client. Make sure you specify host to force it to use network connection.

Belldandy 2 years ago

you mean this?

luca@zero-traccar:~ $ mariadb -h 127.0.0.1 -u traccar -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 40
Server version: 10.5.23-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> status;
--------------
mariadb  Ver 15.1 Distrib 10.5.23-MariaDB, for debian-linux-gnu (aarch64) using  EditLine wrapper

Connection id:          40
Current database:
Current user:           traccar@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         10.5.23-MariaDB-0+deb11u1 Debian 11
Protocol version:       10
Connection:             127.0.0.1 via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:               3306
Uptime:                 5 min 31 sec
Anton Tananaev 2 years ago

Yes, if it works like this, it should work in Traccar as well.

Belldandy 2 years ago

it still does not seems to be willing to cooperate.
Now it's too late, I will retry next weekend, but seems that connection still have something ill.

luca@zero-traccar:/opt/traccar $ sudo java -jar tracker-server.jar conf/traccar.xml
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Exception in thread "main" java.lang.RuntimeException: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) [Guice/ErrorInCustomProvider]: HikariPool$PoolInitializationException: Failed to initialize pool: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
  at DatabaseModule.provideDataSource(DatabaseModule.java:46)
  at DatabaseStorage.<init>(DatabaseStorage.java:48)
      \_ for 2nd parameter
  while locating DatabaseStorage
  at MainModule.provideStorage(MainModule.java:123)
  at TaskClearStatus.<init>(TaskClearStatus.java:29)
      \_ for 2nd parameter
  while locating TaskClearStatus

thank you , in any case. and have a nice week.
E.

Anton Tananaev 2 years ago

What's in your config?

Belldandy 2 years ago

It should have been the same as in the instruction page...
Anyway, to make a long story short, i took the chance of a flu to restart all from scratch once again...
Maybe it was the high fever, this time it managed to start...

the only difference i see in database status is
Connection: Localhost via UNIX socket
instead of Connection: 127.0.0.1 via TCP/IP

Now i feel my paracetamol is fading out, next i'll insert all the devices and see if it works... I'll be back, if something else does not go well...

thank you