mysql数据库问题(错误信息)汇总

1、mysql 驱动版本问题

错误信息:

 Loading class com.mysql.jdbc.Driver. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver. 
The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

解决方案:

使用了高版本的 mysql 驱动包后(6.0及以后), 对应的 driver 应该从 com.mysql.jdbc.Driver 变成 com.mysql.cj.jdbc.Driver 。

2、mysql 时区问题

错误信息:

 Cause: 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.

永久解决方案:

1)修改 url 串,在后面添加   serverTimezone=UTC 属性即可,如:

jdbc.url=jdbc:mysql://localhost:3306/xxx?serverTimezone=UTC

2)修改 my.ini 配置文件 

default-time_zone = '+8:00'

3、多表操作时,排序规则不一致问题

错误信息:

 ### Error querying database. Cause: java.sql.SQLException: Illegal mix of collations (utf8_swedish_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=' 
### The error occurred while setting parameters 
### Cause: java.sql.SQLException: Illegal mix of collations (utf8_swedish_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1267]; Illegal mix of collations (utf8_swedish_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='; nested exception is java.sql.SQLException: Illegal mix of collations (utf8_swedish_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=' 

解决方案:

上例中,用 a 表的字段与 b 表的字段作为查询条件对比时报错。

由错误信息可知  其中一个字段的排序规则为 utf8_swedish_ci 而另一个为 utf8_general_ci 

将两个字段的排序规则统一即可。

4、插入数据时,主键或唯一键重复问题

错误信息:

### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'xxx' for key 'xxxx' 
### The error may involve xxxx.insert-Inline 
### The error occurred while setting parameters 
; SQL []; Duplicate entry 'xxx' for key 'xxx'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'xxx' for key 'xxx' 

解决方案: 

避免使用重复的主键,可以设置成自增或者UUID等。

5、程序启动时报:Public Key Retrieval is not allowed

错误信息:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed

解决方案:

在连接后面添加 allowPublicKeyRetrieval=true

61040-Too many connections

错误信息:

解决方案:

出现此情况可能是连接池配置量过小 。

找自己的MySQL安装目录,然后打开my.ini配置文件,找到 max_connections 属性,将后面的值调大即可。

如 max_connections=1000 ,然后重启一下mysql,即可。

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值