Linux下快速重置MySQL用户(root)密码方法
skip-grant-tables顾名思义,数据库启动的时候 跳跃权限表的限制,不用验证密码,直接登录。
1.修改配置参数
/etc/my.cnf在[mysqld] 下面加上:
skip-grant-tables
配置项。
2.重启mysql
使得参数生效:
service mysqld restart
注意事项此时所有用户登录当前数据库都是免密码的,所以此时数据库的安全性是非常低的。
4.修改密码
UPDATE mysql.user SET password = PASSWORD('newpass') WHERE user = 'root';mysql5.7后版本使用下面的方法修改密码
update mysql.user set plugin="mysql_native_password" where user="root";
update mysql.user set authentication_string=password('xxxxx') where user='root' and Host = 'localhost';开启远程
GRANT ALL PRIVILEGES ON *.* TO 'userxxxxx'@'%' IDENTIFIED BY 'XXXX' WITH GRANT OPTION;
flush privileges;
5.去掉参数
a.密码修改好了之后再将配置文件中 skip-grant-tables去掉
b.再次重启数据库。