錯誤提示:
The server time zone value ‘¥x¥_¼Ð·Ç®É¶¡’ 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.
解決辦法:
mysql的連接通常都是:
jdbc:mysql://localhost/blog?useUnicode=true&characterEncoding=utf8
直接指定字符集就行了,今天報了這個錯誤,找了下原因,是因為時區的問題。
方法一:
修改url為
jdbc:mysql://localhost/blog?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
方法二:
1.在mysql的命令模式下使用
mysql > select CURTIME();
或
mysql > select now();
看當前時間是否正確,可以看到mysql當前使用的是那一個時區的時間。
2.在Mysql命令行中更改時區
mysql > SET time_zone = '+8:00'; # 此為北京時,我們所在東8區
mysql> flush privileges; # 立即生效
此時mysql時區已更改正確,與系統時區都使用為 Shanghai時間了。
這種方法好像只能在終端上使用,退出終端后時間又會變成原來的,看來只能重啟mysql了。