今天在寫Springboot項目時,連接MySql時出現個錯誤,控制檯輸出: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.
![Springboot項目連接MySql寫了一個bug你也可能遇到](http://p2.ttnews.xyz/loading.gif)
是因為application-local.yml裡面的寫法有問題,所以報個了時區的問題。下圖就是錯誤寫法。
![Springboot項目連接MySql寫了一個bug你也可能遇到](http://p2.ttnews.xyz/loading.gif)
在連接字符串後面加上?serverTimezone=UTC,其中UTC是統一標準世界時間。
連接字符串示例:jdbc:mysql://127.0.0.1:3306/bdproject?serverTimezone=UTC,為了避免中午亂碼的問題,通常還會再後面加上&useUnicode=true&characterEncoding=UTF-8。最終的url寫法就是jdbc:mysql://127.0.0.1:3306/bdproject?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8。這個字符串拼接的時候注意連接符號。
日常bug輸出,每個bug都會出其不意,有時不經意間就製造了一個。
閱讀更多 程序員球迷的日常 的文章