问题描述
我正在尝试创建Wikipedia数据库副本(大约50GB),但是最大的SQL文件存在问题.
I'm trying to create a Wikipedia DB copy (Around 50GB), but having problems with the largest SQL files.
我已经使用linux split实用程序将大小为GB的文件拆分为300 MB的块.例如
I've split the files of size in GB using linux split utility into chunks of 300 MB. e.g.
split -d -l 50 ../enwiki-20070908-page page.input.
在我的服务器上,平均300MB的文件平均需要3个小时. 我已经安装了Ubuntu 12.04服务器操作系统和Mysql 5.5 Server.
On average 300MB files take 3 hours at my server. I've ubuntu 12.04 server OS and Mysql 5.5 Server.
我正在尝试以下操作:
mysql -u username -ppassword database < category.sql
注意:这些文件由插入语句组成,不是CSV文件.
Wikipedia提供了数据库转储供下载,因此每个人都可以创建Wikipedia的副本.您可以在此处找到示例文件:维基百科转储
Wikipedia offers database dumps for download, so everybody can create a copy of Wikipedia.You can find example files here: Wikipedia Dumps
由于MySQL Server的设置,我认为导入速度很慢,但是我不知道应该更改什么.我在具有不错处理器和2GB RAM的计算机上使用标准的Ubuntu MySQL配置.有人可以为我的系统提供合适的配置来帮助我吗?
I think the import is slow because of the settings for my MySQL Server, but I don't know what I should change. I'm using the standard Ubuntu MySQL config on a machine with a decent processor and 2GB RAM. Could someone help me out with a suitable configuration for my system?
我尝试将innodb_buffer_pool_size设置为1GB,但是没有用.
I've tried to set innodb_buffer_pool_size to 1GB but no vains.
推荐答案
由于内存不足50GB(因此无法在内存中缓冲整个数据库),因此瓶颈是磁盘子系统的写入速度.
Since you have less than 50GB of memory (so you can't buffer the entire database in memory), the bottleneck is the write speed of your disk subsystem.
加快进口速度的技巧:
- MyISAM不是事务性的,因此在单线程插入中速度要快得多.尝试加载到MyISAM,然后将表
ALTER
加载到INNODB
- 使用
ALTER TABLE .. DISABLE KEYS
避免逐行更新索引(仅适用于MyISAM) - 将
bulk_insert_buffer_size
设置为插入大小之上(仅限MyISAM) - 设置
unique_checks = 0
,以便不检查唯一约束.
- MyISAM is not transactional, so much faster in single threaded inserts. Try to load into MyISAM, then
ALTER
the table toINNODB
- Use
ALTER TABLE .. DISABLE KEYS
to avoid index updates line by line (MyISAM only) - Set
bulk_insert_buffer_size
above your insert size (MyISAM only) - Set
unique_checks = 0
so that unique constrains are not checked.
有关更多信息,请参见 MySQL手册中的> InnoDB表的批量数据加载.
For more, see Bulk Data Loading for InnoDB Tables in MySQL Manual.
注意:如果原始表具有外键约束,那么将MyISAM用作中间格式是个坏主意.
Note: If the original table have foreign key constraints, using MyISAM as an intermediate format is a bad idea.
这篇关于MYSQL插入大小为GB的巨大SQL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- Use
- 使用