发布作者:
大凯同学
百度收录:
正在检测是否收录...
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
1.登录终端,切换至mysql的bin目录
说明:mysql服务的bin目录以实际环境为准
2 . 执行命令或手动执行,停止MySQL服务
net stop mysql
3.执行如下命令,以安全模式启动MySQL服务。(注意此终端不能关闭)
mysqld.exe --skip-grant-tables
4.登录另一个终端,执行如下命令,登录MySQL数据库,在提示输入密码时直接回车即可。
mysql -uroot -p
5.依次执行如下SQL语句,更新密码,完成后退出。
mysql> use mysql;
Database changed
mysql> set password for root@localhost = password('root');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> update user set password=password("root") where user="root";
Query OK, 3 rows affected (0.02 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
6.关闭步骤四的终端,重启mysql,使用新密码登录成功。
net stop mysql
7.可视化数据库管理软件测试连接
1.编辑MySQL数据库的my.cnf配置文件。
vim /etc/my.cnf
2.在[mysqld]字段下新增如下内容,然后保存退出。
skip-grant-tables
3.执行如下命令,重启MySQL服务。
/etc/init.d/mysqld restart
说明:MySQL启动脚本路径以实际环境为准。
4.登录MySQL数据库并且执行修改语句
/etc/init.d/mysqld restart
mysql> use mysql;
mysql> set password for root@localhost = password('root');
mysql> flush privileges;
5.**再次编辑/etc/my.cnf配置文件,删除或者注释第2步添加的skip-grant-tables。**
6.**重启服务,使用新密码登录。**
/etc/init.d/mysqld restart
—— 评论区 ——