Springboot连接mysql数据库踩坑
我的mysql版本是8.0.17 一开始直接使用springboot提供的默认的mysql驱动,报错:Unknown system variable ‘query_cache_size’
在网上找了原因:mysql驱动版本过低,这个问题的发生意思是query cache在MySQL5.7.20就已经过时了,而在MySQL8.0之后就已经被移除了。于是把mysql驱动版本改为8.0.11,发现还是报错!
最后发现:8.0以上的驱动配置要改为:com.mysql.cj.jdbc.Driver
OK,改成这个新的驱动,接下来的错误:
java.sql.SQLException: 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.
这是貌似跟mysql的时间有关,解决办法:
1.方法1.在语句"jdbc:mysql://localhost:3366/stujdbc “后添加”?serverTimezone=GMT%2B8":
2.更改MySQL中的系统时间(修改my.cnf实现永久修改)
vi /etc/mysql/my.cnf
然后在mysqld下边的配置中添加一行:
default-time_zone = '+8:00'
然后重启mysql
service mysql restart`