Mac Homebrew安装的MySQL无法远程登录的解决
TCatTime 人气:0对于Mac上Homebrew安装的MySQL,默认情况下只能使用本地登录。
而使用其它主机远程登录Mac上的MySQL则会被拒绝访问。
下面修改MySQL的相关配置并使其能被远程主机访问。
1. 登录MySQL
mysql -u root -p -D mysql
2. 修改user表中root用户的Host值
update user set host='%' where user='root';
查看下修改情况:
mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | root | % | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | +------------------+-----------+ 4 rows in set (0.00 sec)
3. 刷新权限
flush privileges;
4. 退出MySQL
exit
5. 修改MySQL服务绑定的IP
对于Homebrew安装的MySQL,默认的配置文件路径是/usr/local/etc/my.cnf:
# Default Homebrew MySQL server config [mysqld] # Only allow connections from localhost bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
将bind-address值修改为0.0.0.0:
# Default Homebrew MySQL server config [mysqld] # Only allow connections from localhost bind-address = 0.0.0.0 mysqlx-bind-address = 127.0.0.1
6. 重启MySQL服务
brew services restart mysql
加载全部内容