將 text 檔案裡的資料匯入到 mysql 資料庫中,資料匯入mysql

來源:互聯網
上載者:User

將 text 檔案裡的資料匯入到 mysql 資料庫中,資料匯入mysql

如題,將 text 檔案裡的資料匯入到 mysql 資料庫中。
我自己具體的實現可以分為幾種了:
1、寫你擅長的程式設計語言 進行讀寫檔案,然後串連資料庫,進行寫入;
2、在 mysql 裡直接進行運行 sql 指令碼語句,進行匯入。

第一個現在就不再說了,簡單。
現在就說說怎麼直接將 .text 檔案利用 sql 語句 進行匯入。
1、首先在資料庫中建立一個表(這裡的表至少要和 你資料裡的欄位進行匹配,即一行存在的欄位數);
2、運行sql指令碼語句:
比如: 你的檔案為 D:/field.txt ; 資料庫表名為 field ; text檔案裡欄位是用定位字元(\t)進行分割;
LOAD DATA INFILE ‘D:/field.txt’ INTO TABLE FIELD FIELDS TERMINATED BY ‘\t’ LINES TERMINATED BY ‘\n’
點擊執行即可得到資料。
建立後表 count 為0

運行 mysql 指令碼語句後

匯入資料 count

在此記錄,以備後需。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.