1.vim /etc/my.cnf 在[mysqld]最后加上如下语句并保存退出
skip-grant-tables
2.重启mysql服务 :
service mysqld restart
3.免密码登陆:
mysql -u root -p
password校验直接回车
select host, user, authentication_string, plugin from user;
use mysql;#选择数据库
4.设置密码为空
update user set authentication_string='' where user='root'; 设置登陆密码为空
5.exit;退出登录。删除第一步中/etc/my.cnf文件最后的 skip-grant-tables。
6.再次重启mysql服务.
7.root用户空密码直接登陆
mysql -u root -p
passwrod:直接回车;
8.重启mysql之后,密码复杂性会发生变化,通过以下命令查看密码等级。
show variables like 'validate_password%';
9.修改密码复杂性(若是想设置简单密码需要这步,复杂密码:大小字母+数字+符号;则不用进行这一步)
mysql8.0操作代码
set global validate_password.policy=0;
mysql5.6操作代码
set global validate_password_policy=0;
10.修改密码,需要设置复杂的密码(字母,数字,特殊符号组合)后重新登陆,如下:
注:这里我是修改的简单密码,若是需要复杂密码直接执行
ALTER user 'root'@'localhost' IDENTIFIED BY '你的密码';
授权远端访问:
create user 'root'@'%' identified with mysql_native_password by '19961103';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
注:这里的密码要保证符合上面的密码复杂度规则。