MySQL数据库密码忘记之后,可以进入linux下修改原始密码,步骤为下。
第一步:登陆服务器管理员权限。
第二步:进入MySQL数据配置文件
[root@VM_0_8_centos ~]# vi /etc/my.cnf
最后一行添加免密码登陆:skip-grant-tables
:wq保存退出。
第三步:重启
[root@VM_0_8_centos ~]# systemctl restart mysqld.service
检查是否启动成功:systemctl status mysqld.service
第四步:免密登陆数据库
[root@VM_0_8_centos ~]# mysql -uroot -p
Enter password:
这里回车就就可进入。
第五步:修改mysql密码
选择数据库:use mysql;
5.7以上版本运行:update user set password= password("newPassword")where user='root';
5.7以下版本运行:update user set authentication_string= password("newPassword")where user='root';
第六步:退出exit、将第二步文件添加的 skip-grant-tables 取消
第七步:重启重复第三步。修改完成,可密码登陆成功。
面向开发过程,记录学习之路。