惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
P
Privacy International News Feed
T
Tenable Blog
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
S
Securelist
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
月光博客
月光博客
T
The Blog of Author Tim Ferriss
Scott Helme
Scott Helme
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
C
Cisco Blogs
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
Security Latest
Security Latest
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
I
InfoQ
Spread Privacy
Spread Privacy
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
A
About on SuperTechFans
博客园_首页
Engineering at Meta
Engineering at Meta
Project Zero
Project Zero
Latest news
Latest news

博客园 - emanlee

ubuntu 设置北京日期时间 mysql 在新电脑上导入,出现错误:ERROR at line 4019: Unknown command '\''. - emanlee 安装 yarn npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本。 - emanlee VS code, 最近打开过哪些项目或文件夹,把这些备份下来,到另外一台电脑上恢复 傲梅分区助手 【好用】 ubuntu 可以使用Windows远程桌面连接吗?【可以】 把xshell的全部连接和密码,从一台Windows 10电脑,迁移到Windows11电脑。 Windows 远程桌面(mstsc)完整迁移方案(含历史连接记录、RDP 配置、保存的账号密码)【可行】 Endnote,如何能完整迁移库和模版 ubuntu 安装 locate “华为杯”第八届中国研究生人工智能创新大赛 pip install django-ranged-response==0.2.0 部署Vue+Django 04c,mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory Ubuntu Server 24.04 安装 MySQL, ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory ubuntu server 24.04: 如何设置默认采用 Xorg 方式登录 Ubuntu Server 24.04 设置锁屏时间 Ubuntu Server 启动过程中,比较慢 Job systemd-networkd-wait-online.service/start running Ubuntu Server 24.04 启用root用户 Ubuntu snap install 安装todesk是否必须检查 CPU 是否支持 AVX / AVX2 命令 Ubuntu Server 24.04下解决SunloginClient 向日葵依赖libgconf-2-4安装问题 Ubuntu Server 24.04 安装图形界面 ubuntu server 24.04 安装 中文输入法 Ubuntu Server 24.04 安装浏览器firefox Ubuntu Server 24.04 安装todesk【先联网,CPU必须支持 AVX / AVX2 】 Ubuntu Server 24.04 安装中文,汉字 Python赋值,什么时候传引用? 大驼峰命名法 python 容易理解类和对象的例子 django+mysql: 如何添加一个新的超级用户? Python 异常体系核心:BaseException 及其四大子类 Python 匿名函数(lambda)举例 Python函数内部的局部变量和全局变量 订书钉规格 在Navicat中复制带有自动增长id字段的表格,如何把新表格的自动增长id重新设置为从1开始 科研02 期刊和会议的质量等级 Vue 2,父组件中点击一个按钮,更新子组件(重新加载子组件) 汉明距离(Hamming distance) Modbus slave模拟的从站 如何主动发送数据给主站 Word中,表格中的文字在一行的偏下方,没有垂直居中 在线把汉字转拼音字母 Navicat中复制并修改MySQL表,保存时,出现未知的列的错误 WinSCP 便携版、绿色版 下载 centos / Linux 上,非管理员用户安装 miniconda FTP 服务器设置(FileZilla Server) Windows主机上的Device/Credential Guard功能与VMware Workstation虚拟化冲突导致 Navicat 备份连接
当数据量很大时,执行 mysql> source filename.sql 很慢,有什么办法更快
emanlee · 2026-05-22 · via 博客园 - emanlee

当数据量很大时,执行 mysql> source filename.sql  很慢,有什么办法更快

我给你最简单、最有效、立刻能上手的提速方案,只做最关键的几步,就能让大 SQL 导入快 10~100 倍,不用改复杂配置。

一、最快方案:执行 source 前,先运行这 4 行(必做)

先登录 MySQL,选中数据库,然后复制执行这 4 行:

SET autocommit = 0;
SET unique_checks = 0;
SET foreign_key_checks = 0;
SET SESSION tx_isolation = 'READ-UNCOMMITTED';
COMMIT;
SET autocommit = 1;
SET unique_checks = 1;
SET foreign_key_checks = 1;

二、比 source 更快:用系统命令行导入(推荐)

不要在 mysql> 里面用 source,直接在 CMD / 终端执行:

mysql -u用户名 -p 数据库名 < filename.sql
mysql -uroot -p testdb < guolei.20260521sql.sql

三、再加 2 个参数,速度再翻倍

mysql -u用户名 -p --max_allowed_packet=1G --net_buffer_length=1M 数据库名 < filename.sql

四、如果你只能用 source(必须在 mysql> 里执行)

USE 你的数据库;
SET autocommit=0;
SET unique_checks=0;
SET foreign_key_checks=0;
SET tx_isolation='READ-UNCOMMITTED';

source filename.sql;

COMMIT;
SET autocommit=1;
SET unique_checks=1;
SET foreign_key_checks=1;

五、为什么原来这么慢?

  • 默认每插入一条就提交一次事务(极慢)
  • 默认每条都检查外键、唯一键(极耗资源)
  • source 会打印大量日志

六、最简单总结(照着做就行)

  1. 导入前关闭自动提交、外键检查、唯一检查
  2. 优先用命令行导入,不要用 mysql> source
  3. 加参数 --max_allowed_packet=1G