我的MySQL数据库中的BLOB字段有问题 - 当上传大于1MB的文件时,我收到错误 Packets larger than max_allowed_packet are not allowed.
这是我尝试过的:
在MySQL查询浏览器中,我跑了一个show variables like 'max_allowed_packet'
给了我1048576.
然后我执行查询set global max_allowed_packet=33554432
后跟show variables like 'max_allowed_packet'
- 它按预期给我33554432.
但是当我重新启动MySQL服务器时,它神奇地回到了1048576.我在这里做错了什么?
奖金问题,是否可以压缩BLOB字段?
Man*_*uel 374
通过在文件的下方或部分中包含单行更改my.ini
或文件:~/.my.cnf
[mysqld]
[client]
max_allowed_packet=500M
Run Code Online (Sandbox Code Playgroud)
然后重新启动MySQL服务,你就完成了.
有关详细信息,请参阅文档.
Teh*_*ike 205
该max_allowed_packet的变量可以在全球范围通过运行查询进行设置.
但是,如果您不在my.ini
文件中更改它(如建议的dragon112),则在服务器重新启动时,该值将重置,即使您全局设置它也是如此.
要将每个人的最大允许数据包更改为1GB,直到服务器重新启动:
SET GLOBAL max_allowed_packet=1073741824;
Run Code Online (Sandbox Code Playgroud)
naw*_*103 85
我的一个初级开发人员在为我修改这个问题时遇到了问题所以我想我会为linux用户更详细地扩展它:
1)开放终端
2)ssh root @ YOURIP
3)输入root密码
4)纳米/etc/mysql/my.cnf(如果命令不被识别为此,首先还是尽量VI然后重复:百胜安装纳米)
5)在[MYSQLD]部分下添加行:max_allowed_packet = 256M(显然可以根据需要调整大小).他错误地把它放在文件的底部,所以它不起作用.
6)Control + O(保存)然后按ENTER(确认)然后按Control + X(退出文件)
7)服务mysqld重启
8)您可以在phpmyadmin上检查变量部分的更改
fst*_*ang 41
我想有些人还想知道如何在PC上找到my.ini文件.对于Windows用户,我认为最好的方法如下:
我从http://bugs.mysql.com/bug.php?id=68516得到了这个答案
zwi*_*ion 19
按照所有说明,这就是我所做的和工作:
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)
Run Code Online (Sandbox Code Playgroud)
因此,正如我们所看到的,max_allowed_packet已在my.ini之外进行了更改.
让我们离开会话并再次检查:
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)
Run Code Online (Sandbox Code Playgroud)
结论,在SET GLOBAL max_allowed_packet = 1073741824之后,服务器将拥有新的max_allowed_packet,直到它重新启动,如前所述.
xpr*_*ros 12
如果在执行备份时出现此错误,max_allowed_packet
可以在my.cnf
特别设置中进行设置mysqldump
.
[mysqldump]
max_allowed_packet=512M
Run Code Online (Sandbox Code Playgroud)
我在执行a时一直遇到这个错误mysqldump
而且我不理解因为我在这个部分my.cnf
下面有这个设置[mysqld]
.一旦我弄清楚我可以设置它[mysqldump]
并设置值,我的备份完成没有问题.
Say*_*yka 10
对于那些运行wamp mysql服务器的人
Wamp托盘图标 - > 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
Run Code Online (Sandbox Code Playgroud)
向下滚动直到找到
[mysqld]
port=3306
explicit_defaults_for_timestamp = TRUE
Run Code Online (Sandbox Code Playgroud)
在其间添加packet_size行
[mysqld]
port=3306
max_allowed_packet = 16M
explicit_defaults_for_timestamp = TRUE
Run Code Online (Sandbox Code Playgroud)
检查它是否适用于此查询
Select @@global.max_allowed_packet;
Run Code Online (Sandbox Code Playgroud)
出现此错误是因为您的数据包含大于设置的值。
只需记下max_allowed_packed=500M
或您可以计算出 500*1024k,并根据需要使用它而不是 500M。
现在只需重新启动MySQL。
许多回答者发现了问题并已经给出了解决方案。
我只想建议另一个解决方案,它是从Mysql Workbench工具中更改Glogal变量值。当然,如果您使用在服务器上本地运行的Workbench(或通过SSH连接)
您只需连接到实例并进入菜单:
服务器->选项文件->网络-> max_allowed_packed
您设置所需的值,然后需要重新启动MySql Service。
归档时间: |
|
查看次数: |
739961 次 |
最近记录: |