日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql快速批量入库_MySQL-批量入库优化

發布時間:2025/3/11 数据库 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql快速批量入库_MySQL-批量入库优化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MySQL批量入庫的方式

循環一條一條入庫

批量入庫

通過程序組合 insert into (字段) tbl vlaues(), vlaues(), vlaues(),...

事務入庫

$autoCommit = (isset($this->startTransaction) ? !$this->startTransaction : true);

$ids = array();

if ($autoCommit) {

$this->startTransaction();

}

foreach ($multiInsertData as $insertData) {

if ($dataKeys !== null) {

// apply column-names if given, else assume they're already given in the data

$insertData = array_combine($dataKeys, $insertData);

}

$id = $this->insert($tableName, $insertData);

if (!$id) {

if ($autoCommit) {

$this->rollback();

}

return false;

}

$ids[] = $id;

}

if ($autoCommit) {

$this->commit();

}

使用 LOAD DATA INFILE 文件導入

Tip: 通過PHP程序處理好對應格式的內容生成文件, 然后放到數據庫服務器中導入操作.

imagecode.txt

http://www.qyule01.fun/media/videos/tmb/000/005/451/1.jpg###100000

http://pic.rmb.bdstatic.com/81923c4cd60b8731b09cc55a0ee82cb8.jpeg###100000

http://pcookie.cnzz.com/app.gif?&cna=Q/1fFKG8SggCAXRVIh2iBCTo###100000

http://inews.gtimg.com/newsapp_ls/0/6134659193_150120/0###100000

load data local infile'/Users/home/xx/temp/xxyun/imagecode.txt'into table imagecode fields terminated by'###'lines terminated by'\n'(url,code);

測試數據

vbox-ubuntu-16.04 2G2核

// 寫入一個文件-本地vbox服務器 run time total :0.47590112686157

// 本地vbox服務器-耗費時間: run time total :46.867498874664

// 本地vbox服務器-去除rand函數: run time total :48.011456012726

// 本地vbox服務器-去除var_dump函數: run time total :0.12039113044739

// 本地vbox服務器-使用insertMulti函數 : run time total :43.925640106201

// 內網服務器-耗費時間: run time total :42.424664020538

相關資料

–secure-file-priv選項問題的解決方法 # show global variables like '%secure_file_priv%';

secure_file_priv 為 NULL 時,表示限制mysqld不允許導入或導出。

secure_file_priv 為 /tmp 時,表示限制mysqld只能在/tmp目錄中執行導入導出,其他目錄不能執行。

secure_file_priv 沒有值時,表示不限制mysqld在任意目錄的導入導出。

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的mysql快速批量入库_MySQL-批量入库优化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。