Monday, August 18, 2014

MySQL exception in RDS:com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'content' at row 1

With default mysql.5.5 RDS DB parameter group you may see an exception getting thrown with the stack below:-

***********
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'content' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4188)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361)
***********

This is probably because MySQL parameter, "max_allowed_packet" is not set. You will have to create a custom db parameter group and then explicitly set the value for "max_allowed_packet" to something like "33554432". You will need to modify the RDS instance and then select "mydbgroup" as the parameter group then check "apply immediate" box. Once the parameter group takes effect, it will show status of "pending-reboot" and then you will have to reboot your RDS instance. 

Once the changes are in place, you can confirm by running the below MySQL commands

************
mysql> SELECT @@max_allowed_packet;
----------------------
@@max_allowed_packet
----------------------
33554432
----------------------
1 row in set (0.00 sec)
************

Alternatively, you can also run AWS CLI command:-

$aws rds-modify-db-parameter-group mydbgroup –parameters “name=max_allowed_packet,value=33554432,method=immediate

No comments:

Post a Comment