使用 ip 访问 mysql 数据库报错,由于默认配置只允许使用 localhost 访问,我们修改下参数即可。
An error occurred while establishing the connection:
Long Message:
null, message from server: "Host 'host.docker.internal' is not allowed to connect to this MySQL server"
Details:
Type: java.sql.SQLException
Error Code: 1130
SQL State: HY000
报错翻译:
空指针,来自服务器的消息:"Host ’ Host .docker.internal’ 不允许连接到 MySQL 服务器"
解决方案:
1、使用 select user,host from user; 命令查看 root 用户的 host,可以看到默认是 localhost。
修改 root 用户的 host 为百分号后就可以用 ip 访问了。update user set host='%' where user='root';
然后 flush privileges;
使之生效。