linux 下忘记 mysql登陆密码解决方法
1、修改my.conf配置文件,添加 skip-grant-tables ,保存并退出,systenctl restart mysqld.service 命令重启服务
2、登陆mysql数据库(直接输入mysql即可),修改登陆用户的密码alter user 用户名@“主机名或ip”(如 root@“localhost”) identified by "new_password";
或 update mysql.user set authentication_string=password("NewPassword") where user="root";
3、使用 flush privileges ; 写入命令
注:执行完步骤“2”会报错“ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement” ,直接忽略执行步骤3即可
4、修改my.conf配置文件,去掉 skip-grant-tables 并重新启动mysqld服务