mysql批量匯出 匯入文字資料

2021-07-12 03:22:46 字數 1074 閱讀 1340

mysql 常用的insert語句:

insert into `test` (`code_no`, `coupon_price`, `get_mobile`,`get_order_code`, `code_get_time`, `code_use_order_id`, `is_coupon_get`,`goods_info_id`) values ('testdx113', '20',null, null, null, null, '0',4856),(...)...;

但有時為了更快速地插入大批量資料,需要從文字中匯入資料或匯出資料到文字。 

故此研究了一下mysql的批量文字資料匯入匯出

mysql 批量匯出語句

select *

into outfile '匯出檔案路徑(f:\\test.txt)'

lines terminated by '\r\n' ()

from 表名;

其中lines terminated by 「\r\n」表示每一行(即每一條記錄)用\r\n分隔,\r\n是window系統的換行符。

mysql 批量匯入語句

load data local infile '匯入檔案路徑(f:\\test.txt)'

into table 表名(資料字段1,資料字段2

,...(需要匯入資料的字段,不需要的可以不寫));

匯入資料:\n代表null

\ntestdx113

2004856

\ntestdx113

2004856

\ntestdx113

2004856

\ntestdx113

2004856 注意:

字段之間的分隔和記錄(行)之間的分隔預設是\t(即tab)和\n。但可以改變,如: 

fields terminated by ',' --欄位用,進行分隔 

lines terminated by ';' --記錄用; 進行分隔 

另外要注意其它作業系統的換行符與windows可能不相同。

MySQL批量匯出 匯入文字資料

首先要在 mysql 中建立對應的資料表,如可取表名為 stu。格式好的文字資料放在乙個 txt檔案 中,每行包含乙個記錄,並且列的順序必須和資料庫 的列次序相同,且各列之間用 特定的分隔符 分隔開。假如格式好的文字資料放在d盤下的 stu.txt檔案中 各列之間的分隔符為tab,那麼匯入資料可以如...

mysql文字匯入匯出資料

mysql文字匯入匯出資料 立測試表,準備資料 首先建立乙個用於測試的表示學生資訊的表,欄位有id 姓名 年齡 城市 薪水。id和姓名不能為空。www.2cto.com create table person id int not null auto increment,name varchar 4...

mysql匯入txt文字資料

按照mysql官方文件指示下 建立資料庫和表 mysql create database menagrie 然後建立表 1 mysql create table pet name varchar 20 owner varchar 20 2 species varchar 20 char 1 birt...