使用ip地址通过jdbc连接阿里云服务器mysql数据库

  • Post author:
  • Post category:mysql


1登录阿里云的控制台,把3306端口开放

2试着连接发现报下面的错误

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.我使用的连接jar是

<dependency>

  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.45</version>
</dependency>

3修改数据库权限-我的数据库是mysql5.7版本的

使用sql语句select user,host from mysql.user;查询,结果如下

使用sql语句update mysql.user set host =’%’ where user = ‘root’更新,结果如下

4重启mysql服务后测试可用



版权声明:本文为qq_32675899原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。