- 设置免密码登陆 编辑mysql配置文件my.cnf(
vim /etc/my.cnf
) 在最后添加skip-grant-tables
保存 - 重启mysql服务: service mysqld restart;
- 免密登录MySQL将旧密码置空
mysql -u root -p
use mysql
-- 将密码置空
update user set authentication_string = '' where user = 'root';
- 删除免密登录配置
删掉配置文件my.cnf 的配置skip-grant-tables
重启服务 service mysqld restart - 修改密码
-- 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
-- 立即生效
flush privileges;