1. vim /etc/my.cnf 在[mysqld]下加入 skip-grant-tables (这个意思是跳过权限验证,可免密码登录 ) 然后保存退出, 重启mysql 2 ./etc/init.d/mysqld restart 登录 3 mysql -u root -p 4. 5.7版本前的mysql运行: update user set password=password("你的密码") where user="用户"; 5.7版本后的mysql运行:update mysql.user set authentication_string=password('你的密码') where user='用户'; 5 exit; #退出 6 编辑my.cnf文件删掉或者注释skip-grant-tables 这一行,然后重启MySQL,/etc/init.d/mysqld restart,否则MySQL仍能免密码登录 7 mysql -u root -p输入密码