82

My application download mails over IMAP and stores them in a MySQL database. Earlier I was supporting mails size upto 10 MB and hence a 'mediumtext' column to store the mail content was enough. Now I need to support mails upto 30MB. So I changed the datatype for the column to 'largetext'. Yesterday a mail with size 25 MB was stored. After that whenever I execute mysqldump command it throws error:

mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when dumping table `ib_mailbox_backup` at row: 3369

Row 3369 contains the 25 MB mail.

In MySQL config I increased the 'max_allowed_packet' from 64M to 512M and it still fails with the same error. Executing the mysqldump command on the same machine where MySQL server is running. How do I solve this?

2
  • 5
    "Row 3369 contains the 25 MB mail." How did you find out the size of row 3369 ?
    – Gopu
    Jan 26, 2015 at 14:48
  • 1
    @Gopu SELECT ... LIMIT 3369,1 Feb 17, 2023 at 7:42

4 Answers 4

203
  1. You can add --max_allowed_packet=512M to your mysqldump command.
  2. Or add max_allowed_packet=512M to [mysqldump] section of your my.cnf (thanks @Varun)

Note: it will not work if it is not under the [mysqldump] section...

7
  • It worked. Is there a way to put this in MySQL configuration file?
    – Varun
    Jan 11, 2012 at 9:50
  • It will not work as this is mysqldump option, but you can create alias if you're under Unix family OS. Jan 11, 2012 at 10:17
  • 7
    Created a section [mysqldump] and added max_allowed_packet=200M to my conf file and it works.
    – Varun
    Jan 12, 2012 at 14:16
  • 7
    I had to use --max-allowed-packet=... as a command line parameter. Check out mysqldump --help if your version doesn't know --max_allowed_packet
    – Martin Nuc
    Feb 26, 2014 at 23:10
  • Editing my.cnf might not be enough as new config files specifically for mysqldump could overwrite the setting in my.cnf (see my answer further below).
    – knipp
    Jul 24, 2017 at 11:34
3

Some of my scripts stopped working after an upgrade to Debian 9 & MariaDB.

MariaDB on Debian introduces a new config file specifically for mysqldump settings (/etc/mysql/conf.d/mysqldump.cnf). If you had set a max_allowed_packet <> 16M in your standard /etc/mysql/my.cnf previously, the new config file will overwrite that setting. So be sure to check this new config file and either delete the entry or adjust it to your needs.

I'm not sure if the change was introduced by the swap from MySQL to MariaDB or if Debian made a change in how the config files are laid out in V9.

0

I had a similar error and would fail with packet size 512M on row 0. It was an innodb table that was apparently damaged (mysqlcheck showed OK). I ended up re-creating the table and then it worked fine with a small packet size of just 128M.

1
  • 3
    Can you explain what the specific problem was here- was it a config issue? Apr 2, 2016 at 1:17
-2

This Work For me.

mysqldump --max_allowed_packet=512M  --routines=true -u [user] [database] > [route and File name].sql
1
  • 1
    This doesn't add any new information compared to the accepted answer from 2012.
    – Richard E
    Mar 11, 2022 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.