mysql外部连接

2020-08-20  本文已影响0人  轻云绿原

要让外部IP连接到本机的数据库

1:在数据库里修改登录用户的来源地址。

mysql数据库.user表.host字段 改成 "%"(任务来源)

2:有可能要改密码的加密方式(plugin),不同的连接工具有差别。

mysql>  update user set plugin = 'mysql_native_password' where user = 'root' and host = '%';

3:要修改my.cnf里的bind-address

注释掉就行。

我是卡在这里。

/usr/local/etc/my.cnf
/usr/local/Homebrew/etc/my.cnf
/usr/local/Cellar/mysql/8.0.17/.bottle/etc/my.cnf

我找到三个文件,头两个改了没用,我把最后一个也改了。就起作用了。

4:改bind-address后,要重启mysql

 brew services restart mysql

8.0+版本

外部不能连接时,新建一个帐号可以解决

create user username@'%' identified  by 'password';
grant all privileges on *.* to username@'%' with grant option;
ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
上一篇 下一篇

猜你喜欢

热点阅读