MySQL 错误 1153 - 收到的数据包大于“max_allowed_pa​​cket” 字节

发布于 2024-07-05 08:22:05 字数 397 浏览 11 评论 0原文

我正在导入 MySQL 转储并收到以下错误。

$ mysql foo < foo.sql 
ERROR 1153 (08S01) at line 96: Got a packet bigger than 'max_allowed_packet' bytes

显然数据库中有附件,这会导致非常大的插入。


这是在我的本地计算机上,一台从 MySQL 包安装了 MySQL 5 的 Mac。

在哪里更改 max_allowed_pa​​cket 才能导入转储?

还有什么我应该设置的吗?

只是运行 mysql --max_allowed_pa​​cket=32M ... 导致了同样的错误。

I'm importing a MySQL dump and getting the following error.

$ mysql foo < foo.sql 
ERROR 1153 (08S01) at line 96: Got a packet bigger than 'max_allowed_packet' bytes

Apparently there are attachments in the database, which makes for very large inserts.


This is on my local machine, a Mac with MySQL 5 installed from the MySQL package.

Where do I change max_allowed_packet to be able to import the dump?

Is there anything else I should set?

Just running mysql --max_allowed_packet=32M … resulted in the same error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

时光暖心i 2024-07-12 08:22:05

您可能必须为客户端(您正在运行以执行导入)和正在运行并接受导入的守护进程 mysqld 更改它。

对于客户端,您可以在命令行上指定它:

mysql --max_allowed_packet=100M -u root -p database < dump.sql

另外,更改 mysqld 部分下的 my.cnf 或 my.ini 文件(通常位于 /etc/mysql/ 中)并设置:< br>

max_allowed_packet=100M

或者您可以在连接到同一服务器的 MySQL 控制台中运行这些命令:(

set global net_buffer_length=1000000; 
set global max_allowed_packet=1000000000;

对数据包大小使用非常大的值。)

You probably have to change it for both the client (you are running to do the import) AND the daemon mysqld that is running and accepting the import.

For the client, you can specify it on the command line:

mysql --max_allowed_packet=100M -u root -p database < dump.sql

Also, change the my.cnf or my.ini file (usually found in /etc/mysql/) under the mysqld section and set:

max_allowed_packet=100M

or you could run these commands in a MySQL console connected to that same server:

set global net_buffer_length=1000000; 
set global max_allowed_packet=1000000000;

(Use a very large value for the packet size.)

聊慰 2024-07-12 08:22:05

在 CENTOS 6 /etc/my.cnf 上,在 [mysqld] 部分下,正确的语法是:

[mysqld]
# added to avoid err "Got a packet bigger than 'max_allowed_packet' bytes"
#
net_buffer_length=1000000 
max_allowed_packet=1000000000
#

On CENTOS 6 /etc/my.cnf , under [mysqld] section the correct syntax is:

[mysqld]
# added to avoid err "Got a packet bigger than 'max_allowed_packet' bytes"
#
net_buffer_length=1000000 
max_allowed_packet=1000000000
#
多孤肩上扛 2024-07-12 08:22:05

我已通过此查询解决了我的问题

SET GLOBAL max_allowed_packet=1073741824;

,并使用此查询检查 max_allowed_pa​​cket

SHOW VARIABLES LIKE 'max_allowed_packet';

I have resolved my issue by this query

SET GLOBAL max_allowed_packet=1073741824;

and check max_allowed_packet with this query

SHOW VARIABLES LIKE 'max_allowed_packet';
谁许谁一生繁华 2024-07-12 08:22:05

使用 max_allowed_pa​​cket 变量发出类似

mysql --max_allowed_pa​​cket=32M 的命令
-u root -p 数据库 < 转储.sql

Use a max_allowed_packet variable issuing a command like

mysql --max_allowed_packet=32M
-u root -p database < dump.sql

最终幸福 2024-07-12 08:22:05

与你的问题有点无关,所以这是谷歌的一个。

如果您没有 mysqldump SQL,则可能是您的 SQL 已损坏。

我刚刚因代码中意外地包含未闭合的字符串文字而出现此错误。 手指粗心的情况时有发生。

这是一个关于失控字符串的奇妙错误消息,感谢 MySQL!

Slightly unrelated to your problem, so here's one for Google.

If you didn't mysqldump the SQL, it might be that your SQL is broken.

I just got this error by accidentally having an unclosed string literal in my code. Sloppy fingers happen.

That's a fantastic error message to get for a runaway string, thanks for that MySQL!

凡尘雨 2024-07-12 08:22:05

在 etc/my.cnf 中尝试将 max_allowed _packet 和 net_buffer_length 更改为

max_allowed_packet=100000000
net_buffer_length=1000000 

如果这不起作用,则尝试更改为

max_allowed_packet=100M
net_buffer_length=100K 

In etc/my.cnf try changing the max_allowed _packet and net_buffer_length to

max_allowed_packet=100000000
net_buffer_length=1000000 

if this is not working then try changing to

max_allowed_packet=100M
net_buffer_length=100K 
奶气 2024-07-12 08:22:05

在 Mac OS X 上使用来自 mysql.com dmg 软件包分发的 MySQL 时重新设置 my.cnf

默认情况下,无法找到 my.cnf。

您需要将/usr/local/mysql/support-files/my*.cnf之一复制到/etc/my.cnf并重新启动mysqld. (如果您安装了 MySQL,则可以在“MySQL 首选项”窗格中执行此操作。)

Re my.cnf on Mac OS X when using MySQL from the mysql.com dmg package distribution

By default, my.cnf is nowhere to be found.

You need to copy one of /usr/local/mysql/support-files/my*.cnf to /etc/my.cnf and restart mysqld. (Which you can do in the MySQL preference pane if you installed it.)

赠佳期 2024-07-12 08:22:05

修复方法是增加 MySQL 守护程序的 max_allowed_pa​​cket。 您可以通过以 Super 身份登录并运行以下命令来对正在运行的守护进程执行此操作。

# mysql -u admin -p

mysql> set global net_buffer_length=1000000;
Query OK, 0 rows affected (0.00 sec)

mysql> set global max_allowed_packet=1000000000;
Query OK, 0 rows affected (0.00 sec)

然后导入你的转储:

gunzip < dump.sql.gz | mysql -u admin -p database

The fix is to increase the MySQL daemon’s max_allowed_packet. You can do this to a running daemon by logging in as Super and running the following commands.

# mysql -u admin -p

mysql> set global net_buffer_length=1000000;
Query OK, 0 rows affected (0.00 sec)

mysql> set global max_allowed_packet=1000000000;
Query OK, 0 rows affected (0.00 sec)

Then to import your dump:

gunzip < dump.sql.gz | mysql -u admin -p database
幸福丶如此 2024-07-12 08:22:05

这可以在服务器部分下的 my.ini 文件(在 Windows 上,位于 \Program Files\MySQL\MySQL Server)中进行更改,例如:

[mysqld]

max_allowed_packet = 10M

This can be changed in your my.ini file (on Windows, located in \Program Files\MySQL\MySQL Server) under the server section, for example:

[mysqld]

max_allowed_packet = 10M
蔚蓝源自深海 2024-07-12 08:22:05

正如 michaelpryor 所说,您必须为客户端和守护进程 mysqld 服务器都更改它。

他的客户端命令行解决方案很好,但 ini 文件并不总是能解决问题,具体取决于配置。

因此,打开一个终端,键入 mysql 以获取 mysql 提示符,然后发出以下命令:

set global net_buffer_length=1000000; 
set global max_allowed_packet=1000000000; 

保持 mysql 提示符打开,并在第二个终端上运行命令行 SQL 执行。

As michaelpryor said, you have to change it for both the client and the daemon mysqld server.

His solution for the client command-line is good, but the ini files don't always do the trick, depending on configuration.

So, open a terminal, type mysql to get a mysql prompt, and issue these commands:

set global net_buffer_length=1000000; 
set global max_allowed_packet=1000000000; 

Keep the mysql prompt open, and run your command-line SQL execution on a second terminal..

彼岸花ソ最美的依靠 2024-07-12 08:22:05

错误:

第 6772 行出现错误 1153 (08S01):收到的数据包大于
“max_allowed_pa​​cket”字节操作失败,退出代码为 1

查询:

SET GLOBAL max_allowed_packet=1073741824;
SHOW VARIABLES LIKE 'max_allowed_packet'; 

最大值:

Default Value (MySQL >= 8.0.3)  67108864
Default Value (MySQL <= 8.0.2)  4194304
Minimum Value   1024
Maximum Value   1073741824

Error:

ERROR 1153 (08S01) at line 6772: Got a packet bigger than
'max_allowed_packet' bytes Operation failed with exitcode 1

QUERY:

SET GLOBAL max_allowed_packet=1073741824;
SHOW VARIABLES LIKE 'max_allowed_packet'; 

Max value:

Default Value (MySQL >= 8.0.3)  67108864
Default Value (MySQL <= 8.0.2)  4194304
Minimum Value   1024
Maximum Value   1073741824
只想待在家 2024-07-12 08:22:05

有时,在 my.ini 中键入设置:

max_allowed_packet = 16M

不起作用。

尝试按如下方式确定 my.ini:

set-variable = max_allowed_packet = 32M

set-variable = max_allowed_packet = 1000000000

然后重新启动服务器:

/etc/init.d/mysql restart

Sometimes type setting:

max_allowed_packet = 16M

in my.ini is not working.

Try to determine the my.ini as follows:

set-variable = max_allowed_packet = 32M

or

set-variable = max_allowed_packet = 1000000000

Then restart the server:

/etc/init.d/mysql restart
[旋木] 2024-07-12 08:22:05

将 max_allowed_pa​​cket 设置为较高值会带来安全风险,因为攻击者可以推送更大尺寸的数据包并使系统崩溃。

因此,需要调整和测试 max_allowed_pa​​cket 的最佳值。

最好在需要时进行更改(使用set global max_allowed_pa​​cket = xxx
而不是将其作为 my.inimy.conf 的一部分。

It is a security risk to have max_allowed_packet at higher value, as an attacker can push bigger sized packets and crash the system.

So, Optimum Value of max_allowed_packet to be tuned and tested.

It is to better to change when required (using set global max_allowed_packet = xxx)
than to have it as part of my.ini or my.conf.

霊感 2024-07-12 08:22:05

我在共享托管环境中工作,并且托管了一个基于 Drupal 的网站。 我也无法编辑 my.ini 文件或 my.conf 文件。

因此,我删除了所有与Cache相关的表,因此我可以解决这个问题。 我仍然在寻找一个完美的解决方案/方法来处理这个问题。

编辑 - 删除表给我带来了问题,因为 Drupal 期望这些表应该存在。 所以我清空了这些表的内容,解决了问题。

I am working in a shared hosting environment and I have hosted a website based on Drupal. I cannot edit the my.ini file or my.conf file too.

So, I deleted all the tables which were related to Cache and hence I could resolve this issue. Still I am looking for a perfect solution / way to handle this problem.

Edit - Deleting the tables created problems for me, coz Drupal was expecting that these tables should be existing. So I emptied the contents of these tables which solved the problem.

神仙妹妹 2024-07-12 08:22:05

将 max_allowed_pa​​cket 设置为与使用 mysqldump 转储时相同(或更多)的值。 如果无法做到这一点,请使用较小的值再次进行转储。

也就是说,假设您使用 mysqldump 转储它。 如果您使用了其他工具,那么您就得靠自己了。

Set max_allowed_packet to the same (or more) than what it was when you dumped it with mysqldump. If you can't do that, make the dump again with a smaller value.

That is, assuming you dumped it with mysqldump. If you used some other tool, you're on your own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文