MySQL匯入TXT文件

2021-07-23 08:50:09 字數 1163 閱讀 5213

mysql

中匯入txt檔案資料的操作指令

學習總結基本的mysql

資料庫匯入匯出操作

www.2cto.com  

1 表tt的格式:

create table `tt` (

`ind` int not null auto_increment,

`name` char(100) default null,

primary key  (`ind`)

) 2 檔案d.txt的內容示例:

1,a

2,b

3,c

3 匯入命令:

mysql> load data infile 'd.txt' into table tt

-> fields terminated by','

-> lines terminated by'\r\n'

注意的地方:

1)、檔案可以使用絕對路徑如'c:/d.txt',否則請將檔案放在資料庫根目錄中

2)、因為字段之間用了逗號隔開,所以必須fields terminated by',',否則匯入失敗

3)、因為winsows中行以「\r\n」隔開,所以必須lines terminated by'\r\n',

如果不設定這個引數,也可匯入成功,但是會多匯入乙個「\r」控制字元,可能在視覺化

mysql工具中看不出字段異樣,但是在mysql命令列中顯示會明顯混亂。

4)、如果表tt非空,且檔案中的ind值在表中有重複,會提示錯誤,並匯入失敗。

只匯入name欄位,檔案d.txt的內容:

a b

c mysql> load data infile 'd.txt' into table tt

-> lines terminated by'\r\n'

-> (name);

load data 命令還支援更複雜的文字格式、檔案編碼等,可參考官方文件。

5 匯出到資料到

windows文字檔案時,為了方便檢視,也需要相同的設定

mysql> select * from tt into outfile 'd.txt'

-> fields terminated by','

-> lines terminated by'\r\n'

mysql 匯入txt文件的問題

學習總結基本的mysql資料庫匯入匯出操作 在進行txt格式資料匯入到mysql時,遇到了很嚴重的問題,首先建立了格式相同的資料庫表,然後我們進行資料匯入,發現遇到錯誤 error 1148 42000 the used command is not allowed with this mysql ...

sqlldr 匯入txt文件

將txt文件匯入oracle資料庫的方法有多種,可以通過pl sql developer裡的text importer工具,但是如果txt文件中的資料量較大,使用text importer會非常慢,感覺像卡住一樣 也可以select for update,直接複製黏貼,但同樣資料量大會很卡。今天嘗試...

mysql 匯入txt MySQL匯入txt檔案

一 如果有id列則需要手動加入id,適用於沒有id的表 load data infile 路徑 txt檔名 into 表名 fields terminated by 分隔符 lines terminated by n 例 load data infile home hui datasets shuj...