標籤:style evel mysqldump into 關閉 eal 技巧 var name
大家都知道myisam讀資料時比innodb要快,但匯入大量表是myisam的記錄特別慢,下面是我總結的mysql在匯入匯出大資料時加快速度的方法
一、使用into outfile匯出、load data匯入資料
1.匯出大資料表(into outfile匯出的資料是文本)mysql> select count(*) from app_china;+----------+| count(*) |+----------+| 17931 |+----------+1 row in set (0.00 sec)mysql> select * from app_china into outfile ‘./app.txt‘; #匯出資料的檔案放在資料目錄Query OK, 17931 rows affected (0.02 sec)
2.匯入大資料表匯出的是文本資料,所以需要先建立表結構
mysql> CREATE TABLE `app_china` (-> `id` int(4) unsigned NOT NULL AUTO_INCREMENT,-> `name` varchar(60) NOT NULL DEFAULT ‘‘,-> `level` tinyint(3) unsigned DEFAULT NULL,-> `upid` int(4) unsigned DEFAULT NULL,-> `area_id` tinyint(3) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘大區id‘,-> `path` varchar(100) NOT NULL,-> `firstLetter` char(1) DEFAULT NULL,-> PRIMARY KEY (`id`)-> ) ENGINE=MyISAM AUTO_INCREMENT=45055 DEFAULT CHARSET=utf8;Query OK, 0 rows affected (0.08 sec)mysql> load data infile ‘./app.txt‘ into table app_china;Query OK, 17931 rows affected (0.07 sec) #17931條資料用時0.07秒Records: 17931 Deleted: 0 Skipped: 0 Warnings: 0
二.使用mysqldump匯出匯入資料1.匯出資料[[email protected] ~]# time mysqldump -uroot -p 27_interna app_china > app_china.sqlEnter password:real 0m2.307suser 0m0.008ssys 0m0.002s2.匯入資料[[email protected] ~]# time mysql -uroot -p 27_interna < app_china.sqlEnter password:real 0m2.545suser 0m0.013ssys 0m0.000s3.使用source匯入這裡不示範了,此方法最慢
三、innodb資料匯入技巧對於類型為innodb的表,在匯入較大資料時調整以下兩個參數將大大提高匯入速度1.關閉自動認可set autocommit=0;2.修改資料寫入磁碟操作set global innodb_flush_log_at_trx_commit=0#預設都為1,匯入完成後請都修改回來
總結:
在匯入myisam大資料量時可以使用mysql直接匯入或者使用into outfile匯出為文本再load data匯入,使用source將會耗費大量時間
mysql匯入匯出資料