skip to Main Content

I have browsed all of the available threads regarding this issue but none of them seem to help solving my problem.

Having pulled my mariadb image with command (on root account using su):

docker pull mariadb:latest

Then running:

docker run -d --name some_name -e MYSQL_ROOT_PASSWORD=some_secret_password -p 1111:3306 -v /volume/path:/volume/path mariadb:latest

Then doing (after this command i get root@some_numbers in prompt so i assume im in root mode):

docker exec -it some_name bash

Then changing in 50-server.cnf following line:

bind_address 172.0.0.1 -> bind_address 0.0.0.0 to supposedly accept all traffic not only from localhost

Then trying to login for the first time:

mariadb -P 1111 --protocol=tcp -u root -p yes, i know about -p to write password like this -pPASSWORD etc. it does not work, also when leaving empty it does not work, not any variant of this command works, all of the proper ones give one, and same result:

ERROR 1045 (28000): Access denied for user 'root'@'some_ip' (using password: YES)

And i have tried it from docker container with root privileges (su mode on), on host machine with root privileges and on remote machine with root privileges all with the same result shown above. I also am aware of this one: link and I am surprised that when being literaly on root account with su mode on I still can not log in.

I also can not do anything to mariadb service to shut it down and restart with skip grant flag as shown here: link

To summarize, I want to get an access to mariadb instance that sits in container on remote server based on ubuntu to access it with another remote machine in the future, but for now after following every step I could find, I am stuck at a simple log in for the first time into database.

2

Answers


  1. I’ve tried your example with both a mariadb 10.5 and 11.6 client and both connect using your described execution.

    e.g:

    $ client/mariadb -P 1111 --protocol=tcp -u root -psome_secret_password
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 4
    Server version: 11.4.2-MariaDB-ubu2404 mariadb.org binary distribution
    
    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)]> s
    --------------
    client/mariadb from 11.6.0-MariaDB, client 15.2 for Linux (x86_64) using  EditLine wrapper
    
    Connection id:      4
    Current database:   
    Current user:       root@::1
    SSL:            Cipher in use is TLS_AES_256_GCM_SHA384, cert is OK
    Current pager:      stdout
    Using outfile:      ''
    Using delimiter:    ;
    Server:         MariaDB
    Server version:     11.4.2-MariaDB-ubu2404 mariadb.org binary distribution
    Protocol version:   10
    Connection:     localhost via TCP/IP
    Server characterset:    utf8mb4
    Db     characterset:    utf8mb4
    Client characterset:    utf8mb3
    Conn.  characterset:    utf8mb3
    TCP port:       1111
    Uptime:         2 min 48 sec
    
    

    The issue is MYSQL_ROOT_PASSWORD=some_secret_password or more modernly MARIADB_ROOT_PASSWORD=some_secret_password is not used after the data volume /volume/path is initialized. Whatever the password was when the volume was created its not currently some_secret_password (or whatever it really was).

    It also might be the case that if your some_secret_password contains characters with shell meanings then those may change what is passed though to the MariaDB server. Quote if unsure like '-psome_secret_password'. For a long time the MariaDB container has been able to handle any password.

    If you are still stuck, reset the password with:

    docker run -d --name some_name -p 1111:3306 -v /volume/path:/volume/path mariadb:latest --skip-grant-tables
    mariadb -P 1111 --protocol=tcp -u root -e 'flush privileges;set password=password=("some_other_secret_password")'
    
    Login or Signup to reply.
  2. Please do not make any modifications. Just use the default values ​​and it will work fine.

    Host 1 – 192.168.56.107

    Run Command:

    docker run 
      -d 
      --name some_name 
      -e MYSQL_ROOT_PASSWORD=yourPassword 
      -p 1111:3306 
      mariadb:latest
    

    Please do not make any modifications. Just use the default values ​​and it will work fine.

    Host 2 – 192.168.56.1

    Run command

    mariadb  -h 192.168.56.107  -P 1111 -u root -p
    

    Result 1

    Enter password: 
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 4
    Server version: 11.4.2-MariaDB-ubu2404 mariadb.org binary distribution
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    

    input SQL Command: SHOW GRANTS FOR 'root'@'%';

    Result 2

    MariaDB [(none)]> SHOW GRANTS FOR 'root'@'%';
    +--------------------------------------------------------------------------------------------------------------------------------+
    | Grants for root@%                                                                                                              |
    +--------------------------------------------------------------------------------------------------------------------------------+
    | GRANT ALL PRIVILEGES ON *.* TO `root`@`%` IDENTIFIED BY PASSWORD '*03F7361A0E18DA99361B7A82EA575944F53E206B' WITH GRANT OPTION |
    | GRANT PROXY ON ''@'%' TO 'root'@'%' WITH GRANT OPTION                                                                          |
    +--------------------------------------------------------------------------------------------------------------------------------+
    2 rows in set (0.001 sec)
    

    input SQL Command:

    SELECT User, Host FROM mysql.user;
    

    Result 3

    MariaDB [(none)]> SELECT User, Host FROM mysql.user;
    +-------------+-----------+
    | User        | Host      |
    +-------------+-----------+
    | root        | %         |
    | healthcheck | 127.0.0.1 |
    | healthcheck | ::1       |
    | healthcheck | localhost |
    | mariadb.sys | localhost |
    | root        | localhost |
    +-------------+-----------+
    6 rows in set (0.002 sec)
    

    I didn’t make any modifications and I was able to connect to the Docker Container on host1 from the other host (host2).

    Java Connection Test – From Host 2 (192.168.56.1)

    JDBC URL: jdbc:mariadb://192.168.56.107:1111/
    User name: root
    Password: yourPassword

    SQL1:

    SHOW GRANTS FOR 'root'@'localhost';
    

    SQL1

    SQL2:

    SHOW GRANTS FOR 'root'@'%';
    

    SQL2

    Using the defaults, without modification, you can connect from other hosts using the root account. I don’t know what your real problem is? I mean everything is working fine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search