主要保护数据库被攻击(没密码状态其他用户也可修改数据库状态)
- 修改MySQL的登录设置
vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
- 保存vi退出,重启MySQL服务
- 进入MySQL
- use mysql
- update user set Password = password(‘new password’) where User = ‘root’;
注 MySQL 5.7 之后没有password字段,而是authentication_string,故上面的语句变成
update user set authentication_string= password('new password') where user= 'root';
- 刷新系统权限
flush privileges ;
- 退出MySQL 将/etc/my.cnf该回去,重启MySQL服务就完成了