The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized 偶然遇到的mysql时区问题
因為換了個電腦用,運行時報了個很少見的異常。如下:
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 異常
和
java.sql.SQLException:?The server time zone value '?D1ú±ê×?ê±??' 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
異常?
看著不像是sql的問題,檢查了下代碼,發(fā)現(xiàn)也沒明顯啥問題,就去查了下。
果然有遇到相同問題的,
1的異常是因為所用的Mysql驅動包已經(jīng)不推薦之前用的mysql驅動類,推薦使用新的mysql驅動類
2的異常是因為mysql時區(qū)問題
?
? 就是上面標紅的SQL異常,我們需要在數(shù)據(jù)庫 URL中設置serverTimezone屬性:
static final String DB_URL = "jdbc:mysql://localhost:3306/RUNOOB" +"?serverTimezone=GMT%2B8";這里的?GMT%2B8?代表是東八區(qū)。當然有更好的辦法就是win + R進入cmd窗口,mysql -u root -p 進入mysql ,然后輸入 set? global time_zone = '+8:00';
尷尬的是登陸時提示沒用mysql命令,果然環(huán)境變量中path路徑中需要添加mysql的bin目錄路徑。
然后重新執(zhí)行下上述命令即可。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結
以上是生活随笔為你收集整理的The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized 偶然遇到的mysql时区问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ddd 企业应用架构模式_灵魂拷问:用了
- 下一篇: mysql gtid 备份恢复_MYSQ