I have a server running MySQL 5.7.42 on Ubuntu Linux. I have a config file in ~/.my.cnf containing login info to connect to it from a shell on the same server:

host     = localhost
user     = root
password = myPassword

The MySQL server is set to read from the default locations, which includes ~/.my.cnf:

mysqld --help --verbose 2>1 | grep "my.cnf"
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

and the client is set to do the same:

mysql --help --verbose 2>1 | grep "my.cnf"
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

/etc/my.cnf doesn't exist, /etc/mysql/my.cnf contains only [mysql], and there are no client sections in anything in /etc/mysql/mysql.conf.d or /etc/mysql/conf.d.

But when I run mysql, it fails, saying:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

but if I run mysql --defaults-file=/.my.cnf, it connects successfully, telling me:

  • the file is readable by the user I'm running the command as
  • it is valid
  • the credentials work.

I have the same style config file, in the same place, with the same ownership and permissions on several other servers and they all work fine.

Why isn't MySQL reading my config file?

  • 1
    Neither of these is true. Option files are supported, and the same docs say that [client] is the section name for all user mysql utilities, including things like mysqldump, whereas [mysql] only applies to the mysql client. mysql_config_editor is a good pointer though.
    – Synchro
    Jun 8 at 8:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.