mysql 匯入資料加速 MySQL加速匯入資料

2021-10-19 18:25:56 字數 1304 閱讀 4710

修改配置

關閉binlog

避免寫入日誌set sql_log_bin = off;

匯入完成還原配置set sql_log_bin=on

調整innodb_flush_log_at_trx_commit

加快資料刷盤速度。set global innodb_flush_log_at_trx_commit=2;

show variables like '%max_allowed_packet%';

set global max_allowed_packet=10485760;

批量insert

mysql執行大批量insert操作時變慢時,提公升速度的方法如下:

修改bulk_insert_buffer_size

若資料庫已存大量資料(幾百萬條),可加大bulk_insert_buffer_size,預設8m,調整為:bulk_insert_buffer_size=100m

使用insert delayed into

改寫所有insert into語句為insert delayed into,insert delayed不同之處在於:立即返回結果,後台執行insert。

insert多條資料insert into table values('11','11'),('22','22'),('33','33')...;

匯入/出備份

使用load data infile

load data infile輸入檔案,可以是來自select into outfile命令。

load data infile語句能快速從文字檔案中讀取資料行到表中load data infile "/data/mysql/e.sql" into table e fields terminated by ',';

注:by後面的分隔符,可以是自定義,取決於檔案內容。

使用select into outfileselect * from e into outfile "/data/mysql/e.sql";

或select * into outfile "/data/mysql/e.sql" from e;

mysqlimport

mysql mysqlimport,能從檔案中將格式化資料匯入資料庫,若有乙個大批量資料的檔案,此工具能夠快速匯入。

mysqlimport可看作是load data infile sql語句的命令列介面,大部分引數選項都是一致的,資料來源可以是select into outfile匯出的檔案。mysqlimport -u root -ppassword [--local] dbname filename.sql [option]

加速 MySQL 匯入匯出的方法

mysql匯出的sql語句在匯入時有可能會非常非常慢,在處理百萬級資料的時候,可能匯入要花幾小時。在匯出時合理使用幾個引數,可以大大加快導 入的速度。e 使用包括幾個values列表的多行insert語法 max allowed packet 客戶端 伺服器之間通訊的快取區的最大大小 net buf...

加速MySQL匯入匯出的方法

加速mysql匯入匯出的方法 mysql匯出的sql語句在匯入時有可能會非常慢,在處理百萬級資料的時候,可能匯入要花幾小時。在匯出時合理使用幾個引數,可以大大加快匯入的速度。e 使用多行insert語法,給出更緊縮並且更快的插入語句 max allowed packet 客戶端 伺服器之間通訊的快取...

mysql匯入情況 MySQL 匯入資料

mysql 匯入資料 本章節我們為大家介紹幾種簡單的 mysql 匯出的資料的命令。1 mysql 命令匯入 使用 mysql 命令匯入語法格式為 mysql u使用者名稱 p密碼 要匯入的資料庫資料 runoob.sql 例項 mysql uroot p123456 runoob.sql 以上命令...