Freitag, 17. Februar 2017

MySQL Error: Access denied for user 'root'@'localhost' (using password: NO) when running sript

I wanted to run a python script to reformat my MySQL Database, but everytime I try to run it, it shows the error

MySQL Error 1045: Access denied for user 'root'@'localhost' (using password: NO)
Unable to determine MySQL version
I found out that in the script there is no trigger for username or password, so I should run the script as the right user. The problem is my recovery enviroment is chrooted and so I can't just su - USER to change user and than run the script with mysql privileges.

The script offers another option that I don't know before: A userbased .my.cnf file. With this script mysql reads out the login credentials from a file in the user account, in my case: /root/.my.cf.

I wrote into it:
[client]
password="1234"
[mysqladmin]
 user = root
 password = 1234
[mysql]
 user = root
 password = 1234
[mysqldump]
 user = root
 password = 1234
I don't know if I need all parameters because when I run the script without the [client]-section it won't start but with it the error has gone.