1、MySQL的Too many connections错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: “Too many connections”。
原因:
因为你的mysql安装目录下的my.ini中设定的并发连接数太少或者系统繁忙导致连接数被占满。
解决方式:
打开MYSQL安装目录打开MY.INI找到max_connections(在大约第93行)默认是100 一般设置到500~1000比较合适,重启mysql,这样1040错误就解决啦。
max_connections=1000
一定要重新启动MYSQL才能生效:
net stop mysql
net start mysql
2、Caused by: java.sql.SQLException: Could not retrieve transation read-only status server
Caused by: java.sql.SQLException: Unknown system variable ‘tx_read_only’
异常产生原因:
1.JDBC驱动版本过低
2.数据库版本过低
本人使用版本:mysql驱动6.0,数据库版本5.7
去maven官网库查找对应的驱动:
https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.11
3、严重: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
原因:
使用killall 或者 kill -9直接杀死java进程,导致相关内存没有及时释放.
解决:
cmd进入tomcat的bin目录,执行shutdown.exe来停止tomcat.
4、The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more than one time zone问题
解决:
我们需要在数据库 URL中设置serverTimezone属性(serverTimezone=GMT%2B8),这里的 GMT%2B8 代表是东八区。
附上jdbc.properties文件内容:
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/test_db?useSSL=false&serverTimezone=GMT%2B8
username=root
password=root
#定义初始连接数
initialSize=0
#定义最大连接数
maxActive=20
#定义最大空闲
maxIdle=20
#定义最小空闲
minIdle=1
#定义最长等待时间
maxWait=60000