【问题标题】:mysql .my.cnf not reading credentials properly?mysql .my.cnf 没有正确读取凭据?
【发布时间】:2013-10-10 15:48:33
【问题描述】:

我可以使用以下行连接到 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 有什么问题?

另外,它与此处提到的匿名用户无关: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 

【问题讨论】:

  • 你确定你没有混合你的密码和主机配置吗?
  • 这是我的主目录中的 .my.cnf 文件,而不是 /etc/my.cnf 中的文件。这东西应该在那个里面吗?
  • 否,但如果您收到'myusername'@'mypassword' 之类的消息,则似乎您在host= 之后输入了密码,并且可能在password= 之后输入了您的主机。如果应该是'myusername'@'localhost'...
  • 抱歉,这只是我的问题中的一个错误
  • 嗯,我想到了一个最后的猜测:如果你的密码中有 = 和其他字符......你需要引用密码,这样做帮忙?

标签: mysql


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

    • 是的,这是 Wrikken 在 10 月份在 cmets 中的回答,并且奏效了。 (安迪后来发布了完全相同的内容)
    猜你喜欢
    • 2019-08-14
    • 2021-12-31
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    • 2021-02-16
    相关资源
    最近更新 更多