on Chapter3, Page 36: unable to connect to database, check login_user and login_password
kayg04 opened this issue · 5 comments
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'\")"
}
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.
@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.
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.
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.