MySQL用臨時表造資料

2022-09-23 03:57:08 字數 885 閱讀 5358

採用臨時表

建立臨時資料表tmp_table

create table tmp_table (

id int,

primary key (id)

);

用 python或者bash 生成 100w 記錄的資料檔案(python瞬間就會生成完)

python(推薦):python -c "for i in range(1, 1+1000000): print(i)" > base.txt

匯入資料到臨時表tmp_table中

mysql> load data infile '/users/ljtjintao/temp/base.txt' replace into table tmp_table;

query ok, 1000000 rows affected (2.55 sec)

records: 1000000 deleted: 0 skipped: 0 warnings: 0

千萬級資料 20秒插入完成。

注意:

匯入資料時有可能會報錯,原因是mysql預設沒有開secure_file_priv

(這個引數用來限制資料匯入和匯出操作的效果,例如執行load data、select … into

outfile語句和load_file()函式。這些操作需要使用者具有file許可權。)

解決辦法:

在mysql的配置檔案中(my.ini 或者 my.conf)中新增secure_file_priv = users/ljtjintao/temp/, 然後重啟mysql解決。

mysql 臨時表 漢字 mysql的臨時表用法

delimiter use qgroupdata drop procedure if exists ex print bg kdd search create definer root procedure ex print bg kdd search where varchar 2000 查詢條件 ...

mysql臨時表更新 MySql 臨時表

今天在專案中遇到乙個,當mysql的in語句中資料量很大時,建立乙個臨時表的例子。於是樓主整理了一下關於臨時表的知識,與大家分享一下 首先,臨時表只在當前連線可見,當關閉連線時,mysql會自動刪除表並釋放所有空間。因此在不同的連線中可以建立同名的臨時表,並且操作屬於本連線的臨時表。建立臨時表 cr...

mysql 臨時表 限制 Mysql臨時表

當你建立臨時表的時候,你可以使用temporary關鍵字。如 create temporary table tmp table name varchar 10 not null,passwd char 6 not null 或create temporary table if not exists ...