-- 当不能用service mysqld start启动,找到mysql.server的位置
find / -name mysql.server
-- 关掉mysql
/opt/mysql/support-files/mysql.server stop
-- 打开/etc/my.cnf配置文件
vim /etc/my.cnf
-- 跳过授权表启动MySQL服务程序 修改my.cnf配置,添加 skip_grant_tables=1启动设置, 然后保存退出
skip_grant_tables=1
-- 输入mysql直接进入数据库
mysql
-- 修改密码
update mysql.user set authentication_string=password('123456') where user='root' and host='localhost';
FLUSH PRIVILEGES; #刷新授权列表
exit; #退出数据库
-- 重新以正常方式启动MySQL服务程序,验证新密码
vim /etc/my.cnf #打开my.cnf配置表 删掉skip_grant_tables=1这行 并保存退出
-- 正常登陆
mysql -uroot -p123456
-- 远程登陆权限
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
FLUSH PRIVILEGES; #刷新授权列表
-- 如遇 Your password does not satisfy the current policy requirements 报错,则修改mysql 密码策略
SHOW VARIABLES LIKE 'validate_password%';
set global validate_password_policy=LOW;
set global validate_password_length=6;
FLUSH PRIVILEGES;
关联网址:
https://blog.csdn.net/tianshuhao/article/details/90822788
https://www.cnblogs.com/zgqbky/p/11720406.html
https://blog.csdn.net/hello_world_qwp/article/details/79551789