mysql .my.cnf没有正确阅读凭证?

时间:2013-10-10 15:48:34

标签: mysql

我可以使用以下行连接到mysql:

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

这是我的主页目录中的.my.cnf(不是/etc/my.cnf):

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

我的/etc/my.cnf中似乎还有一个客户端部分:

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

但是当我在终端输入“mysql”时,我得到:

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

我的my.cnf出了什么问题?

另外,它与anon用户无关,如下所述:MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)

以下是建议查询的结果:

>>>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 

2 个答案:

答案 0 :(得分:7)

正如@Wrikken在评论中所说,如果您引用密码并且密码包含=;等字符,则会有效。

答案 1 :(得分:1)

您的问题是您错过了密码周围的引号。

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

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

搜索“这是一个典型的用户选项文件:”并查看他们在那里说明的示例。