目录
问题描述:
使用IDEA自带的Database配置一个本地的mysql连接,通过cmd查看数据库连接正常。用户名、密码、URL、需要的驱动皆无误,却总是报如下错误:com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.
java.lang.RuntimeException: com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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.
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:422)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
问题原因:
通过错误原因描述可知,测试连接失败的原因是:服务器时区无法识别或代表多个时区。
解决办法:
在URL后增加以下代码,指定时区:
?serverTimezone=UTC
IDEA连接数据库如果有其他问题,可以按照以下方法逐步排除:
- 检查相关的驱动是否安装
- 检查mysql的服务是否开启
- 使用cmd工具,尝试连接数据库,连接成功表示服务已开启。
- 确定数据库的账号密码输入正确。
如果还有其他问题,推荐参考官方文档:IDEA官方文档--数据库连接