- 配置文件 MySQL 免密码登录
vim /etc/my.cnf
在 pid 开头的下一行加入
skip-grant-tables
保存并退出
- 重启 MySQL 服务
service mysqld restart
- 免密码登录
mysql -u root -p
提示输入密码时直接回车
- 选择 mysql 数据库
use mysql;
- 在 mysql 数据库的 user 表中查看当前 root 用户的相关信息
select host, user, authentication_string, plugin from user;
- 将默认的 root 密码置空
use mysql;
update user set authentication_string='' where user='root';
- 退出 mysql命令行
quit;
- 删除 /etc/my.cnf 文件最后的 skip-grant-tables
vim /etc/my.cnf
删除 skip-grant-tables 并保存退出
- 重启 MySQL 服务
service mysqld restart
- 重新登录 MySQL
mysql -u root -p
提示输入密码时直接回车,因为我们已经把密码置空了。
- 使用 ALTER 修改 root 用户密码
ALTER user 'root'@'localhost' IDENTIFIED BY 'YourPwd213*';
设置一个安全点的密码即可