【问题标题】:Can't set root MySQL password to null无法将 root MySQL 密码设置为 null
【发布时间】:2016-10-02 01:41:21
【问题描述】:

在安装mysql的时候,我没有在root密码字段中放任何东西,但是当我运行mysql -u root时,我仍然得到Access denied for user 'root'@'localhost'

我在没有授权表sudo mysql_safe --skip-grant-tables &的安全模式下启动了mysql,然后毫无问题地使用mysql -u root进入。

然后我做了use mysql; update user set authentication_string=null where user='root';,我得到了:

Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

有人知道为什么密码没有更新吗?

【问题讨论】:

    标签: mysql ubuntu-16.04 mysql-5.7


    【解决方案1】:

    你忘了

    FLUSH PRIVILEGES;
    

    一步一步会是这样的

    停止 MySQL 服务器。

    sudo /etc/init.d/mysql stop
    

    启动mysqld配置。

    sudo mysqld --skip-grant-tables &
    

    以 root 身份登录 MySQL。

    mysql -u root mysql
    

    用您的新密码替换 YOURNEWPASSWORD!

    UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
    

    【讨论】:

    • 看看最后几行输出。最后一行应该是Rows matched: 1 Changed: 1 Warnings: 0FLUSH PRIVILEGES; 在这里没有做任何事情,因为没有任何改变。此外,在 mysql 5.7 中,password 字段被替换为authentication_string
    • 是的,你是对的,我没有看到“0 行受影响”。选择user表,查看表中存在的root用户
    【解决方案2】:

    我必须将插件设置为mysql_native_password,所以密码重置部分如下所示:

    update user set authentication_string=password(''), plugin='mysql_native_password' where user='root'; FLUSH PRIVILEGES;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-21
      • 2018-06-02
      • 2011-01-07
      • 2023-03-16
      • 1970-01-01
      • 2015-10-26
      • 2016-10-13
      相关资源
      最近更新 更多