前段时间更新了一下自己MySQL的版本,结果运行自己的javaweb项目直接报错(错误如下)
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.
后面按照网上建议,有两种解决办法,一是往项目中的连接字符串后加“?serverTimezone=GMT%2B8”,二是通过mysql命令行模式下动态修改,第一种方法亲测无效,就第二种管用,所以这里着重说通过mysql命令行模式下动态修改的解决方法,首先win+R ,输入cmd,调出cmd命令行框,然后输入mysql -u root -p 并输入账号密码登入mysql(成功登入的话,cmd界面如下图)
登入之后,先输入show variables like “%time_zone%”; 查看当前时区(如下图)
这里system_time_zone为空很正常,说明system使用系统时区,接下来分别输入set global time_zone = ‘+8:00’; set time_zone = ‘+8:00’; 这样当前全局时区和会话时区就修改成功了,最后输入flush privileges;让当前变更立即生效,这样时区错误就被解决了,另外如果使用了这个方法,切记不要修改项目中的连接字符串,否则还是会遇到时区错误