Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql .my.cnf not reading credentials properly?

Tags:

mysql

I can connect to mysql using the following line:

mysql -u myusername -p
(enters password into terminal)
>>>Welcome to the MySQL monitor.  Commands end with ; or \g.
>>>Your MySQL connection id is 51
>>>Server version: 5.6.10-log Source distribution

Here is my .my.cnf in my home directory (not /etc/my.cnf):

[client]
user = myusername
password = mypassword
host = localhost

There also appears to be a client section in my /etc/my.cnf:

# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port     = 3306
socket      = /tmp/mysql.sock

However when I just type "mysql" into the terminal, I get:

ERROR 1045 (28000): Access denied for user 'myusername'@'localhost' (using password: YES)

What is wrong with my my.cnf?

ALso, it has nothing to do with anon user as mentioned here: MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)

Here is the result of a suggested query:

>>>mysql --print-defaults
>>>mysql would have been started with the following arguments:
>>>--port=3306 --socket=/tmp/mysql.sock --no-auto-rehash --user=myusername --password=mypassword --host=localhost 
like image 912
Tommy Avatar asked Oct 10 '13 15:10

Tommy


2 Answers

As @Wrikken said in the comments, it will work if you quote your password and the password contains characters such as = or ;.

like image 127
Andy Avatar answered Nov 18 '22 15:11

Andy


Your problem is that you are missing the quotes around the password.

[client]
user = myusername
password = "mypassword"
host = localhost

http://dev.mysql.com/doc/refman/5.7/en/option-files.html

Search for "Here is a typical user option file:" and see the example they state in there.

like image 4
mimoralea Avatar answered Nov 18 '22 15:11

mimoralea