【MySQL】centos 7 忘记数据库密码
vim /etc/my.cnf文件;
在[mysqld]后添加skip-grant-tables(登录时跳过权限检查)
重启MySQL服务:sudo systemctl restart mysqld
登录mysql,输入mysql –uroot –p;直接回车(Enter)
输入:set password for 'root'@'localhost'=password('admin');
如果报:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
输入:flush privileges;
再次输入:set password for ‘root’@‘localhost’=password(‘Admin123@qwe’);
为避免麻烦,再次设置远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'Admin123@qwe' WITH GRANT OPTION;
flush privileges;
退出:exit
再把my.ini的skip-grant-tables删除或者注释掉
重启MySQL:sudo systemctl restart mysqld