【问题标题】:Access denied for user 'user'@'localhost' on MySQLMySQL 上用户 'user'@'localhost' 的访问被拒绝
【发布时间】:2012-08-02 21:05:48
【问题描述】:

我正在尝试将我连接到数据库 MySQL 服务器,但控制台显示我 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 我不知道为什么。请帮我。在我的文件my.cnf 我有这样的东西,

[mysqld]
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# To allow mysqld to connect to a MySQL Cluster management daemon, uncomment
# these lines and adjust the connectstring as needed.
#ndbcluster
#ndb-connectstring="nodeid=4;host=localhost:3306"

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[ndbd]
# If you are running a MySQL Cluster storage daemon (ndbd) on this machine,
# adjust its connection to the management daemon here.
# Note: ndbd init script requires this to include nodeid!
connect-string="nodeid=2;host=localhost:3306"

[ndb_mgm]
# connection string for MySQL Cluster management tool
connect-string="host=localhost:3306"

[client]
socket=/tmp/mysql.sock

谢谢。

【问题讨论】:

  • 你能展示你如何通过控制台连接吗? (如果在命令行上提供,则省略密码)
  • 当然,Hectors-MacBook-Pro:~ hlozano$ mysql -uroot -p
  • 安装时设置密码了吗? :) 只是在密码提示下点击Enter 没有帮助吗?你确定你输入了正确的密码? (很抱歉有明显的问题,只是想确定一下):)
  • 哦,当然,我重新安装了 MySQL 服务器,因为没有启动数据库。当我重新启动我的 MAC 没有进入数据库。
  • 如果你真的不记得pass了,你可以在你的my.cnf的[mysqld]部分添加skip_grant_tables,重启服务器就可以不用密码了,然后你就可以了通过更新mysql.user 表来更改密码并重新启动mysql,删除skip_grant_tables 选项。

标签: mysql database mysql-error-1045


【解决方案1】:

如果你真的不记得密码了,你可以在my.cnf[mysqld]部分添加skip_grant_tables,重启服务器,它会让你在没有密码的情况下进入,然后你可以通过更新来更改密码mysql.user 表并重新启动 mysql 删除 skip_grant_tables 选项。

【讨论】:

    【解决方案2】:

    -p 标志表示需要密码。输入您输入的要求密码的内容后,应该有第二个提示。例如:

    $ mysql -u root -p
    $ Enter password: 
    

    然后你输入密码。

    【讨论】:

      猜你喜欢
      • 2021-07-11
      • 1970-01-01
      • 2017-01-27
      • 2018-04-26
      • 1970-01-01
      • 2022-01-20
      • 2016-06-21
      • 2023-04-07
      • 2015-01-31
      相关资源
      最近更新 更多