mysqldump导数报错error 2008处理办法

mysqldump导数报错error 2008处理办法

mysqldump导出dump文件时收到MySQL客户端从服务器获取数据时内存耗尽的报错。

🍌报错信息:

bash 复制代码
mysqldump: Out of memory (Needed 2356236304 bytes)
mysqldump: Got error: 2008: MySQL client ran out of memory when retrieving data from server

🐐可能原因:

单次导出的表行数太多,超过了mysql客户端的内存限制(可能是max_allowed_packet参数,默认256M)。

🐯解决办法:

mysqldump命令加上--single-transaction --skip-opt --extended-insert --quick参数。

也可以单独加上--opt参数,但是生产环境不建议,因为会锁表。

如果需要忽略包含特定字符的表,使用多个--ignore-table参数指定。

导出DBNAME库中的所有表,但不包括TABLE_1和TABLE_2:

bash 复制代码
mysqldump -h127.0.0.1 -P3306 -uroot --set-gtid-purged=OFF \
--single-transaction --skip-opt --add-drop-database --extended-insert --quick \
--ignore-table=DBNAME.TABLE_1 --ignore-table=DBNAME.TABLE_2 \
-B DBNAME > dump_DBNAME_`date +%F`.sql

拼接表名清单:

sql 复制代码
select group_concat(concat_ws('.',table_schema,table_name) separator ' --ignore-table=') 
as not_need_table_list
from information_schema.tables
where table_schema = 'DBNAME' and table_name like '%2023%'\G

📖 重要参数含义官方解释:

  • --opt

    This option, enabled by default, is shorthand for the combination of --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset. It gives a fast dump operation and produces a dump file that can be reloaded into a MySQL server quickly.

    Because the --opt option is enabled by default, you only specify its converse, the --skip-opt to turn off several default settings. See the discussion of mysqldump option groups for information about selectively enabling or disabling a subset of the options affected by --opt.

  • --quick

    This option is useful for dumping large tables. It forces mysqldump to retrieve rows for a table from the server a row at a time rather than retrieving the entire row set and buffering it in memory before writing it out.

  • --extended-insert

    Write INSERT statements using multiple-row syntax that includes several VALUES lists. This results in a smaller dump file and speeds up inserts when the file is reloaded.

References

1 https://dba.stackexchange.com/questions/157649/outofmemory-exception-duing-mysqldump

2 https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#option_mysqldump_opt

3 https://mp.weixin.qq.com/s?__biz=MzI2NzM1OTM4OA==\&mid=2247496679\&idx=1\&sn=bc9391542d1b42c64e1d49632c4cf969\&chksm=ea82b614ddf53f0225e2f7249f907f46552283bdb1970d5b340fc94ed9a72638044444542811\&scene=27

相关推荐
万亿少女的梦1687 分钟前
基于Spring Boot、Vue.js和MySQL的超市管理系统设计与实现
java·vue.js·spring boot·mysql·管理系统
weixin_3077791325 分钟前
Linux下Docker Compose里运行的MySQL数据库故障诊断Shell脚本
linux·运维·mysql·docker·自动化
私人珍藏库1 小时前
[Android] PocketPal -本地离线AI助手+大模型部署神器
android·人工智能·app·软件·多功能
listening7772 小时前
HarmonyOS 6.1 跨端实战:用ArkUI-X把电商App同时跑在Android/iOS上
android·ios·harmonyos
爱笑鱼2 小时前
Handler(三):主线程、HandlerThread、Binder 线程到底怎么区分?
android
w139548564222 小时前
鸿蒙实战:报告与雷达图 ReportDao
android·华为·harmonyos·鸿蒙系统
爱笑鱼2 小时前
Handler(二):MessageQueue 为什么不是普通队列?
android
阿巴斯甜3 小时前
Android Studio 新版 Logcat
android
辉灰笔记3 小时前
第一篇:MySQL8.0生产备份实战|XtraBackup全自动全量+增量备份(钉钉告警+异地Binlog归档)
数据库·mysql·钉钉·运维开发
监督者修3 小时前
从零构建 GIS 数据引擎:方案驱动架构的设计与实践
android·架构·kotlin