数据库忘记密码

[root@localhost]# mysql -uroot -p

Enter password:

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

root 密码忘记了。
解决思路:目前是进入不了数据库的情况,所以我们要考虑是不是可以跳过权限。因为在数据库中,MySQL 数据库中 user 表记录着我们用户的信息。

解决方法:启动 MySQL 数据库的过程中,可以这样执行:

/usr/local/mysql/bin/mysqld_safe –defaults-file=/etc/my.cnf  –skip-grant-tables &

--skip-grant-tables  # 关闭连接层的验证功能
--skip-networking    # 关闭TCP/IP协议

这样启动,就可以不用输入密码,直接进入 MySQL 数据库了。然后在修改你自己想要改的 root 密码,然后重启 mysql。

update mysql.user set password=password('root123') where user='root';

#新密码为 root123

5.7版本:

update mysql.user set authentication_string=password('root123') where user='root';

参考:
http://www.yunweipai.com/archives/22031.html

原文地址:https://www.cnblogs.com/klvchen/p/9907600.html