今天安装了MySQL8.0.25,这版本很新了。修改root密码都没问题,但是在允许指定ip的时候与之前的方法不一样。
直接上操作步骤:
- 安装MySQL8并启动服务
systemctl restart mysqld
- 在配置文件中加入跳过密码选项
-
#/etc/my.cnf #在[mysqld]下面添加一行 skip-grant-tables
-
保存并重启服务
systemctl restart mysqld
-
将旧密码置空
mysql -u root -p # 进入MySQL后执行 use mysql; #将密码置空 update user set authentication_string = '' where user = 'root'; #[错误示范] update user set authentication_string = '123456' where user = 'root';
-
注释密码跳过选项
#skip-grant-tables
- 重启MySQL服务
systemctl restart mysqld
- 修改密码
#提示输入密码时直接敲回车,刚刚已经将密码置空了 mysql -u root -p #修改密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
问题就出在这一步,我这里只能把%改成localhost,改成%和其它ip地址都报错
- 解决方法:把%改成localhost就可以在本地登录了
update user set host='localhost' where user='root';
- 授权远程访问
grant all privileges on *.* to root@'%';
- 想远程登录,可以新建一个用户,然后授权,再远程连接
END