MySQL 错误 1153 - 收到的数据包大于“max_allowed_packet” 字节
我正在导入 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_packet
才能导入转储?
还有什么我应该设置的吗?
只是运行 mysql --max_allowed_packet=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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
您可能必须为客户端(您正在运行以执行导入)和正在运行并接受导入的守护进程 mysqld 更改它。
对于客户端,您可以在命令行上指定它:
另外,更改 mysqld 部分下的 my.cnf 或 my.ini 文件(通常位于 /etc/mysql/ 中)并设置:< br>
或者您可以在连接到同一服务器的 MySQL 控制台中运行这些命令:(
对数据包大小使用非常大的值。)
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:
Also, change the my.cnf or my.ini file (usually found in /etc/mysql/) under the mysqld section and set:
or you could run these commands in a MySQL console connected to that same server:
(Use a very large value for the packet size.)
在 CENTOS 6 /etc/my.cnf 上,在 [mysqld] 部分下,正确的语法是:
On CENTOS 6 /etc/my.cnf , under [mysqld] section the correct syntax is:
我已通过此查询解决了我的问题
,并使用此查询检查 max_allowed_packet
I have resolved my issue by this query
and check max_allowed_packet with this query
使用
max_allowed_packet
变量发出类似mysql --max_allowed_packet=32M 的命令
-u root -p 数据库 < 转储.sql
Use a
max_allowed_packet
variable issuing a command likemysql --max_allowed_packet=32M
-u root -p database < dump.sql
与你的问题有点无关,所以这是谷歌的一个。
如果您没有 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!
在 etc/my.cnf 中尝试将 max_allowed _packet 和 net_buffer_length 更改为
如果这不起作用,则尝试更改为
In etc/my.cnf try changing the max_allowed _packet and net_buffer_length to
if this is not working then try changing to
在 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 restartmysqld
. (Which you can do in the MySQL preference pane if you installed it.)修复方法是增加 MySQL 守护程序的 max_allowed_packet。 您可以通过以 Super 身份登录并运行以下命令来对正在运行的守护进程执行此操作。
然后导入你的转储:
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.
Then to import your dump:
这可以在服务器部分下的
my.ini
文件(在 Windows 上,位于 \Program Files\MySQL\MySQL Server)中进行更改,例如:This can be changed in your
my.ini
file (on Windows, located in \Program Files\MySQL\MySQL Server) under the server section, for example:正如 michaelpryor 所说,您必须为客户端和守护进程 mysqld 服务器都更改它。
他的客户端命令行解决方案很好,但 ini 文件并不总是能解决问题,具体取决于配置。
因此,打开一个终端,键入 mysql 以获取 mysql 提示符,然后发出以下命令:
保持 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:
Keep the mysql prompt open, and run your command-line SQL execution on a second terminal..
错误:
查询:
最大值:
Error:
QUERY:
Max value:
有时,在 my.ini 中键入设置:
不起作用。
尝试按如下方式确定 my.ini:
或
然后重新启动服务器:
Sometimes type setting:
in my.ini is not working.
Try to determine the my.ini as follows:
or
Then restart the server:
将 max_allowed_packet 设置为较高值会带来安全风险,因为攻击者可以推送更大尺寸的数据包并使系统崩溃。
因此,需要调整和测试
max_allowed_packet
的最佳值。最好在需要时进行更改(使用
set global max_allowed_packet = xxx
)而不是将其作为 my.ini 或 my.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.
我在共享托管环境中工作,并且托管了一个基于 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 ormy.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.
将 max_allowed_packet 设置为与使用 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.