目錄
問題描述:
使用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官方文檔--數據庫連接