Docker: Access denied for user 'traccar'@'172.33.0.98'

Andreaa year ago

I get this error:

Access denied for user 'traccar'@'172.20.0.45'

but I can regularly connect to the db with the user traccar and the password specified in the traccar.xml file, I guess that the problem is the @'172.20.0.45', how can I remove it?

Here is my docker-compose:

version: "3"
services:
    db:
        image: mariadb
        container_name: traccar-MySQL_db
        command: --default-authentication-plugin=mysql_native_password
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /var/docker/traccar-MySQL/db-datavolume:/var/lib/mysql
            - /var/docker/traccar-MySQL/mysql:/etc/mysql/conf.d
            - /var/docker/traccar-MySQL/mysql/backup:/opt/mysql/backup
        ports:
            - "127.0.0.1:3306:3306"
        labels:
            - traefik.enable=false
        environment:
          MYSQL_ROOT_PASSWORD: root_PW
          MYSQL_USER:  traccar
          MYSQL_PASSWORD: traccar_PW
        restart: unless-stopped
        networks:
          internal_bridge:
            ipv4_address: "172.33.0.99"
    traccar:
        image: traccar/traccar:latest
        container_name: traccar-MySQL_app
        depends_on:
            - db
        restart: unless-stopped
        volumes:
            - /var/docker/traccar-MySQL/traccar.xml:/opt/traccar/conf/traccar.xml:ro
            - /var/docker/traccar-MySQL/logs:/opt/traccar/logs:rw
        ports:
            - "127.0.0.1:5027:5027"
            - "127.0.0.1:8082:8082"
              #        labels:
              #            - traefik.http.routers.traccar.rule=Host(`web.${DOMAIN}`)
              #            - traefik.http.services.traccar_web.loadbalancer.server.port=8082
        networks:
          internal_bridge:
            ipv4_address: "172.33.0.98"

networks:
  internal_bridge:
    external: true
<?xml version='1.0' encoding='UTF-8'?>

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

<properties>

    <entry key='config.default'>./conf/default.xml</entry>

    <!--

    This is the main configuration file. All your configuration parameters should be placed in this file.

    Default configuration parameters are located in the "default.xml" file. You should not modify it to avoid issues
    with upgrading to a new version. Parameters in the main config file override values in the default file. Do not
    remove "config.default" parameter from this file unless you know what you are doing.

    For list of available parameters see following page: https://www.traccar.org/configuration-file/

    -->

    <entry key='database.driver'>com.mysql.cj.jdbc.Driver</entry>
    <entry key='database.url'>jdbc:mysql://db:3306/traccar?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'>traccar</entry>
    <entry key='database.password'>traccar_PW</entry>

     <entry key='mail.smtp.host'>smtp.gmail.com</entry>
    <entry key='mail.smtp.port'>465</entry>
    <entry key='mail.smtp.ssl.enable'>true</entry>
    <entry key='mail.smtp.from'>my_email_address</entry>
    <entry key='mail.smtp.auth'>true</entry>
    <entry key='mail.smtp.username'>my_email_address</entry>
    <entry key='mail.smtp.password'>my_email_password</entry>

    <!-- position forwarding -->
    <entry key='forward.enable'>true</entry>
    <entry key='forward.json'>true</entry>
    <entry key='forward.url'>http://172.33.0.120:1880/traccar</entry>

</properties>
Anton Tananaeva year ago

You need to set up a user with remote access permissions. How did you create your current user?

Andreaa year ago

How did you create your current user?

Well...I didn't, I've never created a user on a mysql docker, they get always created with the docker compose (as it did this time, but maybe not with remote access).
Now I've created the user with remote access with these commands:

CREATE USER 'traccar'@'172.33.0.98' IDENTIFIED BY 'USER_PW';
GRANT ALL ON *.* TO 'traccar'@'172.33.0.98';
FLUSH PRIVILEGES;

But I still get the same error...

Anton Tananaeva year ago

The IP address doesn't seem to match. Instead of 'traccar'@'YOUR.IP.ADDRESS' you can use 'traccar'@'%' to allow all IP addresses.

Andreaa year ago

I've done it
GRANT ALL ON *.* TO 'traccar'@'%';
but nothing...I still get the same error :(

Andreaa year ago

When I tried to connect to the db with the user traccar (from CLI), I succeded and I was connecting to the DB from 172.33.0.200.

Anton Tananaeva year ago

Have you created a new user with 'traccar'@'%'?

Andreaa year ago

Have you created a new user with 'traccar'@'%'?

Yes, I did.
I've noticed that there isn't any database named traccar, shouldn't it be already there?

Anton Tananaeva year ago

You have to create it.

Andreaa year ago

Oh, ok. I may have missed this step in the instructions, or it may be missing.
Thanks!