mysql8.0 开启远程登录

  1. 首先查看防火墙状态 systemctl status firewalld,关闭防火墙 systemctl stop firewalld
  2. 修改 /etc/mysql/mysql.conf.d/mysqld.cnf文件,其中的bind-address改为0.0.0.0
  3. 输入命令(mysql -uroot -p)登入mysql数据库
  4. 执行下面语句查看权限
use mysql;
select host, user, authentication_string, plugin from user;
 
查看user表的root用户Host字段是localhost,说明root用户只能本地登录,现在把他改成远程登录
update user set host='%' where user='root';

'%'表示所有ip都可以连接,相当于0.0.0.0
5. 刷新权限

flush privileges;
  1. 使用navicat连接,如果出现密码加密规则报错可参考下面解决方案:
    MySQL8.0之前的版本密码加密规则:mysql_native_password,
    MySQL8.0密码加密规则:caching_sha2_password
    所以需要修改mysql加密规则
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
  1. 其它:如果需要支持 root - localhost(或者其他IP,例如127.0.0.1)可以使用插入语句
    insert user (user, host, ssl_cipher, x509_issuer, x509_subject) values(‘root’, ‘localhost’, ‘’, ‘’, ‘’);

插入之后再查看user表:(注意 ssl_cipher, x509_issuer, x509_subject这几个字段没有默认值,不设置会提示错误)

猜你喜欢

转载自blog.csdn.net/weixin_44387339/article/details/125839597