【备忘】MySQL8修改密码和允许指定IP访问,与网上现有的有区别

今天安装了MySQL8.0.25,这版本很新了。修改root密码都没问题,但是在允许指定ip的时候与之前的方法不一样。

直接上操作步骤:

  1. 安装MySQL8并启动服务
    systemctl restart mysqld
  2. 在配置文件中加入跳过密码选项
  3. #/etc/my.cnf
    #在[mysqld]下面添加一行
    skip-grant-tables
  4.  保存并重启服务

    systemctl restart mysqld
  5. 将旧密码置空

    mysql -u root -p
    
    # 进入MySQL后执行
    use mysql;
    
    #将密码置空
    update user set authentication_string = '' where user = 'root';
    #[错误示范]
    update user set authentication_string = '123456' where user = 'root';
  6. 注释密码跳过选项

    #skip-grant-tables
  7. 重启MySQL服务 
    systemctl restart mysqld
  8. 修改密码
    #提示输入密码时直接敲回车,刚刚已经将密码置空了
    mysql -u root -p 
    
    #修改密码
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

    问题就出在这一步,我这里只能把%改成localhost,改成%和其它ip地址都报错
     

  9. 解决方法:把%改成localhost就可以在本地登录了
    update user set host='localhost' where user='root';
  10. 授权远程访问
    grant all privileges on *.* to root@'%';
  11. 想远程登录,可以新建一个用户,然后授权,再远程连接

END

おすすめ

転載: blog.csdn.net/qq_15941409/article/details/118733454