背景
今天有項(xiàng)目進(jìn)行sonar掃描時(shí),報(bào)錯(cuò)了,控制臺(tái)的日志輸出如下:

報(bào)錯(cuò)信息
查看原因
查看了web.log,發(fā)現(xiàn)是數(shù)據(jù)庫配置問題
Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1656853 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
問題出在 SonarQube 生成一個(gè)巨大的報(bào)告, 然后嘗試上傳它的壓縮包時(shí), 導(dǎo)致 HTTP 500, 因?yàn)?MySQL 拒絕接受這樣一個(gè)大的請求正文。
解決辦法
更改服務(wù)器mysql配置 (my. cnf文件), 以增加 packed大小 (從默認(rèn) 10MB, 到任何大于你的報(bào)告大小):

[mysqld]
max_allowed_packet = 25M
重新啟動(dòng) MySQL 和sonar服務(wù)來生效。
在jenkins端執(zhí)行掃描后,發(fā)現(xiàn)依然還是報(bào)錯(cuò),再次查看web.log,發(fā)現(xiàn)報(bào)錯(cuò)信息又變了:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: The size of BLOB/TEXT data inserted in one transaction is greater than 10% of redo log size. Increase the redo log size using innodb_log_file_size.
查資料發(fā)現(xiàn)還是數(shù)據(jù)庫配置這塊的問題,在服務(wù)器mysql配置 (my. cnf文件)中,增加innodb_log_file_size的配置,如下:
[mysqld]
max_allowed_packet = 25M
innodb_log_file_size=256M
同樣重啟 MySQL 和sonar服務(wù),再次掃描,發(fā)現(xiàn)上傳報(bào)告這塊就OK啦!