最近新搭建了一个mysql,运行查询语句语句时报出错误:’com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1550606 > 1048576). You can change this value on the server by setting the max_allowed_packet variable.’
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1550606 > 1048576). You can change this value on the server by setting the max_allowed_
packet' variable.
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3915)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2598)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2825)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
at com.hq.sql.Mysql.insert(Mysql.java:152)
at com.hq.sql.SqlExcution.query2Insert(SqlExcution.java:90)
at com.hq.schedule.Schedule.main(Schedule.java:27)
产生的主要原因就是,查询返回的数据量比较大,而允许返回的”max_allowed_packet”太小,导致以上错误。
在linux系统下,找到/etc/my.cnf文件,修改max_allowed_packet=50M,重启mysql,问题解决。
在linux登陆mysql,运行命令 show tables;出现错误:
改为/usr/bin/mysql -uroot -ppwd问题解决。
--转自