报错
ERROR 2003: Can't connect to MySQL server on 'localhost' 的错误
连接本机,ip 端口都正常,用户名密码和默认数据全都正确,而报以上错误无法连接的情况
解决办法
5.0驱动无法连接8.0服务器
修改驱动版本
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
改为
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
报错2
The server time zone value '乱码' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
解决方案
第一种,访问数据库的URL 后面加上时区。
jdbc:mysql://localhost:3306/jpaLearn?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
serverTimezone=UTC 或GMT%2B8
此处GMT%2B8代表东八区
第二种:修改MySQL数据库的时区
输入:show variables like '%time_zone%';
输入: set global time_zone='+8:00';
网友评论