mysql支持IPV6
开启IPV6连接支持
[mysqld]
bind-address = ::
重启mysql!
修改用户权限可由任意ip访问
update user set host = '%' where user ='root'; #更改权限表,使 mysql可以远程连接
flush privileges;
使用netstat查看端口绑定
[root@xa-05-001 software]# netstat -an | grep 3306
tcp6 0 0 :::3306 :::* LISTEN
0.0.0.0:3306,表示监听端口绑定IPv4,只支持IPv4地址连接
:::3306:表示监听端口绑定IPv4和IPv6,支持IPv4和IPv6地址连接
测试是否可通过IPV6访问
mysql -h 2409:8c70:3a50:657::e -uroot -p123456
SpringBoot通过IPV6连接mysql
# 按如下格式修改数据库url
url: jdbc:mysql://address=(protocol=tcp)(host=2409:8c70:3a50:657::e)(port=3306)/demo?
若直接将url改成ipv4会报错:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
转载来源:移动云开发者社区