mysql匯入匯出資料

來源:互聯網
上載者:User

標籤: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匯入匯出資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.