1、开启MySQL远程连接
mysql -u root -p #进入MySQL数据库后进行一下操作。
mysql> use mysql;
mysql> update user set user.Host=’%’ where user.User=‘root’;
mysql> flush privileges;
注:将Host设置为‘%’表示任意IP都能连接MySQL,也可以将‘%’改为指定ip
如果远程连接遇到如下报错:
Unable to load authentication plugin 'caching_sha2_password'.
原因: 是因为mysql8使用的是caching_sha2_password加密规则。
解决方法:
修改远程连接用户的加密规则。
mysql> ALTER USER ‘test’@’%’ IDENTIFIED WITH mysql_native_password BY ‘12345’;
修改配置文件。
#vi /etc/my.cnf
加入下面内容:default_authentication_plugin=mysql_native_password
2、关闭MySQL远程连接
如果有关闭远程连接的需求,其实我们只需要Host恢复成默认设置(只能本地连接)即可,如下: