Connect to Traccar mysql database

Beto3 years ago

Hello, I need to connect to the database that Traccar brings by default, I am creating a web page and I need to connect to it to bring data from the tc_devices table.
I have to upload my page to a server where I have traccar right there and the database the ip of my server is the following
138. #. #. #. #: 8082
How do I make my connection since I have tried to upload my page to the server and executable but it does not connect me to the database.
can anybody help me..

MADCOW3 years ago

you can host your website on another server and connect to Traccar MySQL via Remote IP.

Are you using Ubuntu + MySQL + Traccar?

Beto3 years ago

It is correct I am using Ubunto, Mysql and Traccar

MADCOW3 years ago

open up your mysqld.cnf file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

avigate to the line that begins with the bind-address

bind-address = 127.0.0.1
To
bind-address = 0.0.0.0

After changing this line, save and close the file (CTRL + X, Y, then ENTER if you edited it with nano).

Then restart the MySQL service to put the changes you made to mysqld.cnf into effect:

sudo systemctl restart mysql

Enter MySQL
sudo mysql

mysql -u root -p

mysql> RENAME USER 'root'@'localhost' TO 'root'@'138. #. #. #. #'; <- Your IP

Alternatively, you can create a new user account that will only connect from the remote host with the following command:

CREATE USER 'newuser'@'138. #. #. #. #'' IDENTIFIED BY 'password';

Then grant the new user the appropriate privileges for your particular needs.

GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD on . TO 'root'@'138. #. #. #. #' WITH GRANT OPTION;

mysql> FLUSH PRIVILEGES;

mysql> exit

sudo ufw allow from remote_IP_address to any port 3306 or sudo ufw allow 3306

Restart traccar service

Enjoy

Warning: Make backups are suggestions

Beto3 years ago

I appreciate you I will try that way