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

Tom*_*mmy 6 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
Run Code Online (Sandbox Code Playgroud)

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

[client]
user = myusername
password = mypassword
host = localhost
Run Code Online (Sandbox Code Playgroud)

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

# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port     = 3306
socket      = /tmp/mysql.sock
Run Code Online (Sandbox Code Playgroud)

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

ERROR 1045 (28000): Access denied for user 'myusername'@'localhost' (using password: YES)
Run Code Online (Sandbox Code Playgroud)

my.cnf有什么问题?

此外,它与anon用户无关,如下所述:MySQL ERROR 1045(28000):拒绝访问用户'bill'@'localhost'(使用密码: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 
Run Code Online (Sandbox Code Playgroud)

And*_*ndy 7

正如@Wrikken在评论中所说,如果您引用密码并且密码包含=或等字符,它将起作用;.


mim*_*lea 5

您的问题是您缺少密码周围的引号。

[client]
user = myusername
password = "mypassword"
host = localhost
Run Code Online (Sandbox Code Playgroud)

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

搜索“这是一个典型的用户选项文件:”并查看其中所述的示例。