How to change max_allowed_packet size

后端 未结 12 1581
星月不相逢
星月不相逢 2020-11-22 09:16

I am having a problem with BLOB fields in my MySQL database - when uploading files larger than approx 1MB I get an error Packets larger than max_allowed_packet are not

相关标签:
12条回答
  • 2020-11-22 09:26

    One of my junior developers was having a problem modifying this for me so I thought I would expand this in greater detail for linux users:

    1) open terminal

    2) ssh root@YOURIP

    3) enter root password

    4) nano /etc/mysql/my.cnf (if command is not recognized do this first or try vi then repeat: yum install nano )

    5) add the line: max_allowed_packet=256M (obviously adjust size for whatever you need) under the [MYSQLD] section. He made a mistake of putting it at the bottom of the file first so it did not work.

    enter image description here

    6) Control + O (save) then ENTER (confirm) then Control + X (exit file)

    7) service mysqld restart

    8) You can check the change in the variables section on phpmyadmin

    0 讨论(0)
  • 2020-11-22 09:28

    For those running wamp mysql server

    Wamp tray Icon -> MySql -> my.ini

    [wampmysqld]
    port        = 3306
    socket      = /tmp/mysql.sock
    key_buffer_size = 16M
    max_allowed_packet = 16M        // --> changing this wont solve
    sort_buffer_size = 512K
    

    Scroll down to the end until u find

    [mysqld]
    port=3306
    explicit_defaults_for_timestamp = TRUE
    

    Add the line of packet_size in between

    [mysqld]
    port=3306
    max_allowed_packet = 16M
    explicit_defaults_for_timestamp = TRUE
    

    Check whether it worked with this query

    Select @@global.max_allowed_packet;
    
    0 讨论(0)
  • 2020-11-22 09:31

    Change in the my.ini or ~/.my.cnf file by including the single line under [mysqld] or [client] section in your file:

    max_allowed_packet=500M
    

    then restart the MySQL service and you are done.

    See the documentation for further information.

    0 讨论(0)
  • 2020-11-22 09:32

    I think some would also want to know how to find the my.ini file on your PC. For windows users, I think the best way is as follows:

    1. Win+R(shortcut for 'run'), type services.msc, Enter
    2. You could find an entry like 'MySQL56', right click on it, select properties
    3. You could see sth like "D:/Program Files/MySQL/MySQL Server 5.6/bin\mysqld" --defaults-file="D:\ProgramData\MySQL\MySQL Server 5.6\my.ini" MySQL56

    I got this answer from http://bugs.mysql.com/bug.php?id=68516

    0 讨论(0)
  • 2020-11-22 09:34

    set global max_allowed_packet=10000000000;

    0 讨论(0)
  • 2020-11-22 09:39

    The max_allowed_packet variable can be set globally by running a query.

    However, if you do not change it in the my.ini file (as dragon112 suggested), the value will reset when the server restarts, even if you set it globally.

    To change the max allowed packet for everyone to 1GB until the server restarts:

    SET GLOBAL max_allowed_packet=1073741824;
    
    0 讨论(0)
提交回复
热议问题