起初這樣能短暫解決問題,后來發現每次機器重啟了就還是有這樣的錯誤,還是要執行SQL,很麻煩:
show variables like '%time_zone%'; select now(); set global time_zone = '+8:00'; flush privileges;
其實這個不是spring boot + mybatis的問題, 其實是為了使MySQL JDBC驅動程序的5.1.33版本與UTC時區配合使用,必須在連接字符串中明確指定serverTimezone。
jdbc:mysql://localhost:3306/testdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC