How to change max_allowed_packet size
我的MySQL数据库中的blob字段有问题-当上载大于大约1MB的文件时,我会得到一个错误
以下是我的尝试:
在mysql查询浏览器中,我运行了一个
然后我执行查询
但当我重新启动mysql服务器时,它神奇地回到了1048576。我在这里做错什么了?
额外的问题,是否可以压缩一个blob字段?
1 | max_allowed_packet=500M |
然后重新启动mysql服务,就完成了。
有关更多信息,请参阅文档。
通过运行查询,可以全局设置max_allowed_packet变量。
但是,如果您不在
要将每个人允许的最大数据包更改为1GB,直到服务器重新启动:
我的一个初级开发人员在为我修改这个问题上遇到了问题,所以我想我可以为Linux用户更详细地扩展这个问题:
1)开放式终端
2)ssh根@yourip
3)输入根密码
4)nano/etc/mysql/my.cnf(如果无法识别命令,请先执行此操作或尝试vi,然后重复:yum install nano)
5)在[mysqld]下添加行:max_allowed_packet=256M(显然可以根据需要调整大小)。他犯了一个错误,先把它放在文件的底部,这样它就不起作用了。
6)控制+O(保存),然后输入(确认),然后控制+X(退出文件)
7)服务mysqld重启
8)您可以在phpmyadmin的变量部分检查更改。
我想有些人还想知道如何在电脑上找到my.ini文件。对于Windows用户,我认为最好的方法如下:
我从http://bugs.mysql.com/bug.php得到了这个答案?ID=68516
遵循所有的指示,这就是我所做和工作的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | mysql> SELECT CONNECTION_ID();//This is my ID for this session. +-----------------+ | CONNECTION_ID() | +-----------------+ | 20 | +-----------------+ 1 row in set (0.00 sec) mysql> select @max_allowed_packet //Mysql do not found @max_allowed_packet +---------------------+ | @max_allowed_packet | +---------------------+ | NULL | +---------------------+ 1 row in set (0.00 sec) mysql> Select @@global.max_allowed_packet; //That is better... I have max_allowed_packet=32M inside my.ini +-----------------------------+ | @@global.max_allowed_packet | +-----------------------------+ | 33554432 | +-----------------------------+ 1 row in set (0.00 sec) mysql> **SET GLOBAL max_allowed_packet=1073741824**; //Now I'm changing the value. Query OK, 0 rows affected (0.00 sec) mysql> select @max_allowed_packet; //Mysql not found @max_allowed_packet +---------------------+ | @max_allowed_packet | +---------------------+ | NULL | +---------------------+ 1 row in set (0.00 sec) mysql> Select @@global.max_allowed_packet;//The new value. And I still have max_allowed_packet=32M inisde my.ini +-----------------------------+ | @@global.max_allowed_packet | +-----------------------------+ | 1073741824 | +-----------------------------+ 1 row in set (0.00 sec) |
因此,正如我们所看到的,允许的最大数据包已经从my.ini中更改了。
让我们离开会话并再次检查:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | mysql> exit Bye C:\Windows\System32>mysql -uroot -pPassword Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 5.6.26-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SELECT CONNECTION_ID();//This is my ID for this session. +-----------------+ | CONNECTION_ID() | +-----------------+ | 21 | +-----------------+ 1 row in set (0.00 sec) mysql> Select @@global.max_allowed_packet;//The new value still here and And I still have max_allowed_packet=32M inisde my.ini +-----------------------------+ | @@global.max_allowed_packet | +-----------------------------+ | 1073741824 | +-----------------------------+ 1 row in set (0.00 sec) Now I will stop the server 2016-02-03 10:28:30 - Server is stopped mysql> SELECT CONNECTION_ID(); ERROR 2013 (HY000): Lost connection to MySQL server during query Now I will start the server 2016-02-03 10:31:54 - Server is running C:\Windows\System32>mysql -uroot -pPassword Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.6.26-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SELECT CONNECTION_ID(); +-----------------+ | CONNECTION_ID() | +-----------------+ | 9 | +-----------------+ 1 row in set (0.00 sec) mysql> Select @@global.max_allowed_packet;//The previous new value has gone. Now I see what I have inside my.ini again. +-----------------------------+ | @@global.max_allowed_packet | +-----------------------------+ | 33554432 | +-----------------------------+ 1 row in set (0.00 sec) |
结论,在设置全局max_allowed_packet=1073741824之后,服务器将拥有新的max_allowed_包,直到重新启动,如前面所述。
如果在执行备份时出现此错误,可以在
1 2 | [mysqldump] max_allowed_packet=512M |
在执行
对于运行wamp mysql server的用户
wamp tray icon->mysql->my.ini
1 2 3 4 5 6 | [wampmysqld] port = 3306 socket = /tmp/mysql.sock key_buffer_size = 16M max_allowed_packet = 16M // --> changing this wont solve sort_buffer_size = 512K |
向下滚动到末尾,直到找到
1 2 3 |
在中间添加数据包大小行
1 2 3 4 |
检查它是否与此查询一起工作
许多回答者发现了这个问题,并已经给出了解决方案。
我只想建议另一个解决方案,它是从工具mysql工作台中更改glogal变量值。当然,如果您使用在服务器上本地运行的工作台(或通过ssh连接)。
您只需连接到实例并进入菜单:
Server -> Options File -> Networking -> max_allowed_packed
您设置了所需的值,然后需要重新启动MySQL服务。
对于在AmazonRDS服务上运行MySQL的任何人,此更改都是通过参数组完成的。您需要创建一个新的pg或使用现有的pg(而不是默认的只读pg)。
您应该搜索
回到mysql实例中,如果创建了一个新的pg,那么应该将pg附加到实例中(可能需要重新启动)。如果更改了已附加到实例的pg,则更改将在不重新启动的情况下应用到已附加该pg的所有实例。
出现此错误是因为数据包含的值大于设置值。
记下
现在重启mysql。
如果要在数据库中上载大尺寸图像或数据。只需将数据类型更改为