使用idea连接数据库时,报错。
错误提示:
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: 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.
解决方法如下:
打开Navicat for MySQL里想要连接的数据库,新建查询,在界面中输入:
show variables like '%time_zone%';
set global time_zone='+08:00';
再次测试连接,连接成功!
注意:如果还是不成功,在连接数据库语句的位置,做出如下修改,然后再重复以上的步骤,即可!
我这里使用mybatis框架,因此需要在mybatis核心配置文件里对数据库连接信息进行修改。
在连接的url后面加一些信息
<property name="url" value="jdbc:mysql:///mybatis?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC"/>
修改完上述信息之后,再进行一次上面的步骤,应该就没什么问题了。