帮助中心/最新通知

质量为本、客户为根、勇于拼搏、务实创新

< 返回文章列表

【服务器相关】MySQL8.0修改密码的正确姿势分享

发表时间:2025-09-24 16:09:00 小编:主机乐-Yutio
  • 备注: 清空root密码
  • 停止 MySQL 任务 net stop MySQL

    mysqld 命令 mysqld –console –skip-grant-tables –shared-memory

    无密码进入mysql mysql -u root

    清空root 密码 UPDATE user SET authentication_string="" WHERE user=“root”;

    另一个终端无密码进入


    F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root -p
    Enter password: *******
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

    F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root
    Welcome to the MySQL monitor.Commands end with ; or \g.
    Your MySQL connection id is 7

    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

    mysql> USE mysql;
    Database changed

    mysql> SELECT user, authentication_string FROM user;
    +——————+————————————————————————+
    | user | authentication_string|
    +——————+————————————————————————+
    | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
    | mysql.session| $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
    | mysql.sys| $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
    | root | 123456|
    +——————+————————————————————————+
    4 rows in set (0.34 sec)

    mysql> UPDATE user SET authentication_string=”” WHERE user=”root”;
    Query OK, 1 row affected (0.20 sec)
    Rows matched: 1Changed: 1Warnings: 0

    mysql> SELECT user, authentication_string FROM user;
    +——————+————————————————————————+
    | user | authentication_string|
    +——————+————————————————————————+
    | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
    | mysql.session| $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
    | mysql.sys| $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
    | root ||
    +——————+————————————————————————+
    4 rows in set (0.00 sec)

    mysql> FLUSH privileges;
    Query OK, 0 rows affected (0.10 sec)

    mysql> quit;
    Bye

    停止 mysqld 任务,Ctrl+C 结束任务,或者直接关闭 运行 mysqld 的 cmd 终端。

    需要先停止运行上述 mysqld 任务,否则报错

    F:\MySQL\mysql-8.0.13-winx64\bin>net start mysql
    MySQL 服务正在启动 .
    MySQL 服务无法启动。

    服务没有报告任何错误。

    请键入 NET HELPMSG 3534 以获得更多的帮助。

    先停止上述 mysqld 任务

    F:\MySQL\mysql-8.0.13-winx64\bin>net start mysql
    MySQL 服务正在启动 …
    MySQL 服务已经启动成功。

    现在 mysql root 已经没有了密码

    F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.


    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql>

    总结

    到此这篇关于MySQL8.0修改密码的正确姿势的文章就介绍到这了,更多相关MySQL8.0修改密码姿势内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!


    联系我们
    返回顶部