【问题标题】:ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'错误 1044 (42000): 用户 ''@'localhost' 拒绝访问数据库 'mysql'
【发布时间】:2015-07-18 09:58:45
【问题描述】:

我知道这个问题被问了很多次,我也阅读了很多关于这个问题的问题,但我认为我的不同。

我使用 10.10.3 版的 Mac 和终端来执行我的命令。

我正在尝试创建一个本地数据库(我之前也这样做过),但由于某种原因,访问一直被拒绝。

这是我的终端的样子:

iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -v
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Reading history-file /Users/639/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit;
Writing history-file /Users/639/.mysql_history
Bye
iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database wordpress_db;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'wordpress_db'

如您所见,我可以登录 mysql,但我没有创建数据库的权限。

我尝试像这样登录:

$ /usr/local/mysql/bin/mysql -u root

还有:

$ /usr/local/mysql/bin/mysql -u root -p

我没有密码,但是没有密码也可以进入mysql,然后就不能创建数据库了。

选择 current_user();返回:

mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| @localhost     |
+----------------+
1 row in set (0,00 sec)

【问题讨论】:

    标签: mysql macos command-line terminal


    【解决方案1】:

    尝试使用 --skip-grant-tables 启动 mysql

    mysqld --skip-grant-tables
    

    然后在没有用户名/密码的情况下使用 mysql 命令行连接到您的 mysqld

    shell> mysql
    

    然后发出命令

    > mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
    >        WHERE User='root'; mysql> FLUSH PRIVILEGES;
    

    【讨论】:

    • 感谢您的回答!我做了 mysqld,连接到 mysql 做了命令但没有工作.. 错误 1142 (42000): UPDATE command denied to user ''@'localhost' for table 'user
    • 由于我的系统上没有mysqld二进制文件,我不得不在[mysqld]下添加skip-grant-tables/etc/my.cnf并运行service mysqld restart来启用它
    【解决方案2】:

    首先,试试这个命令:

    sudo dpkg-reconfigure mysql-server-5.5
    

    但将 5.5 替换为您当前的 mysql-server 版本,您将被要求输入新的 root 密码。

    如果这不起作用,请尝试手册中的these instructions

    【讨论】:

    • 我已经重新安装了 mysql,这对我有用。感谢您的回答。我现在不能尝试,但会记住,如果问题再次出现。
    【解决方案3】:

    我有同样的问题。 我所要做的就是退出 shell 并使用mysql -u root -p 再次登录到我的 mysql shell。

    这将提示输入密码。 由于我在设置时没有使用密码,所以我按下了回车键。

    我希望这对你也有用:)。

    【讨论】:

      猜你喜欢
      • 2021-06-01
      • 2012-02-08
      • 1970-01-01
      • 2019-08-23
      • 2016-02-04
      • 2021-07-26
      • 2020-05-09
      • 2013-12-24
      • 2018-04-20
      相关资源
      最近更新 更多