mysql 数据库导入导出
1.关掉binlog,
2.所有要导入的表改为myisam
3.修改max_allowed_package ,多大根据你的实际情况
因为你已经dump好了,所以这些mysqldump的参数就改不了,记得有个批量插入的参数
根据我的经历,你的7G数据导入时间缩短不止一半,30分钟以内搞定
使用下面的命令
select .. into outfile
load data infile
关闭binlog
再调整
max_allowed_packet
innodb_autoinc_lock_mode=2
bulk_insert_buffer_size
innodb_log_buffer_size=8M
innodb_buffer_pool_size
innodb_log_file_size
这些参数,会很快的,2000W的表(2.5g的文本数据文件),普通服务器,3-5分钟搞定
另外,记得在select into outfile的时候按照主键排序导出,否则,如果数据无序,会很慢,慢得可能不止一个数据量级
c:\>mysql -h localhost -u root -p mydb2 < e:\mysql\mydb2.sql
MYSQL快速导入本地数据
MYSQL提供了从本地文件快速导数据的命令,具体说明如下:
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name' [REPLACE | IGNORE] INTO TABLE tbl_name [CHARACTER SET charset_name] [{FIELDS | COLUMNS} [TERMINATED BY 'string'] [[OPTIONALLY] ENCLOSED BY 'char'] [ESCAPED BY 'char'] ] [LINES [STARTING BY 'string'] [TERMINATED BY 'string'] ] [IGNORE number LINES] [(col_name_or_user_var,...)] [SET col_name = expr,...]
实验:导入233M文件的数据
表结构如下:
mysql> SHOW COLUMNS FROM load_file_test;
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| mid | int(10) | YES | | NULL | |
| time | int(10) | YES | | NULL | |
| type | tinyint(4) | YES | | NULL | |
+-------+------------+------+-----+---------+-------+
3 rows in set (0.12 sec)
文件数据格式:
1450025|2|1343145600
1586865|1|1343145600
2557075|2|1343145600
2663240|2|1343145600
3787375|2|1343145600
4293640|1|1343145600
执行结果:
mysql> LOAD DATA LOCAL INFILE '/usr/local/wwwroot/texas/fansPrizeData/2012-12' INTO TABLE load_file_test FIELDS TERMINATED BY '|' LINES
TERMINATED BY '\n' (mid,type,time);
Query OK, 11116864 rows affected (2 min 25.11 sec)
Records: 11116864 Deleted: 0 Skipped: 0 Warnings: 0
二百多兆的数据,大概花了两分半钟,还算是比较快的。