Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on Chapter3, Page 36: unable to connect to database, check login_user and login_password #578

Open
kayg04 opened this issue Mar 17, 2024 · 4 comments

Comments

@kayg04
Copy link

kayg04 commented Mar 17, 2024

On page 36 of the book, the command fails with the following error message. I am thinking mysql needs some more configuration before access is allowed?

$ ansible db -b -m mysql_user -a "name=django host=% password=12345 priv=*:*:ALL host=localhost state=present"
[WARNING]: Found both group and host with same name: db
db | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (1698, \"Access denied for user 'root'@'localhost'\")"
}
@kayg04
Copy link
Author

kayg04 commented Mar 17, 2024

I had to specify login_user and login_password to get it working. I do understand I had the wrong command with priv=*:*:ALL instead of priv=*.*:ALL but even with that corrected, it did not / does not work.

@AndrewO
Copy link

AndrewO commented Jun 27, 2024

@kayg04 What do you use for login_user and login_password? I'm getting the same thing when I do ansible db -b -m mysql_user -a 'name=django host=% password=12345 priv=*.*:ALL state=present login_user=root login_password=""'

But if I SSH into the machine as root and run mysql I can get this:

MariaDB [(none)]> status
--------------
mysql  Ver 15.1 Distrib 10.5.25-MariaDB, for Linux (aarch64) using  EditLine wrapper

Connection id:          5
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         10.5.25-MariaDB MariaDB Server
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 10 min 0 sec

So it would appear root@localhost can login that way.

@AndrewO
Copy link

AndrewO commented Jun 27, 2024

Just noticed in my example that when I logged in locally and connected it was using the Unix socket. So I did:

$ ansible db -b -m mysql_user -a "name=django host=% password=12345 \
   priv=*.*:ALL state=present login_unix_socket=/var/lib/mysql/mysql.sock

...and it worked. Thinking I might have messed up the firewall configuration since I can't seem to login to the db from my host machine.

@badrelmazaz
Copy link

This command worked for me:

ansible db -b -m mysql_user -a "name=django host=% password=django \
   priv=*.*:ALL state=present login_unix_socket=/var/run/mysqld/mysqld.sock"

Credits to this stackoverflow thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants