您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關MYSQL如何使用infile/outfile的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
由于現有的東家要求使用MYSQL數據庫,所以最近也開始了對MYSQL數據庫的進一步的研究,首先介入的當然是一些正常的應用了:
outfile/infile的靈活:
今天接觸了下mysql下的outfile和infile感覺和實際使用很貼切,不像ORACLE那么商業化,任何操作都要封裝成自己的接口來實現、操作,MYSQL直接通過一個簡單的語句就完成了數據的導入、導出,滿足了日常的靈活性與可控性。
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
[REPLACE | IGNORE]
INTO TABLE tbl_name
[FIELDS
[TERMINATED BY 'string']
[[OPTIONALLY] ENCLOSED BY 'char']
[ESCAPED BY 'char' ]
]
[LINES
[STARTING BY 'string']
[TERMINATED BY 'string']
]
[IGNORE number LINES]
[(col_name_or_user_var,...)]
[SET col_name = expr,...)]
demo:
示例文件:
e.txt
===========================
1 2 1 2 1 2 3 4 1 2 3 4 3 4 ==============================
ab
==============================
1,2;3,4
==============================
mysql> load data infile 'd:e.txt' into table test1; Query OK, 7 rows affected (0.13 sec) Records: 7 Deleted: 0 Skipped: 0 Warnings: 0 mysql> load data infile 'd:e.txt' replace into table test1; Query OK, 7 rows affected (0.06 sec) Records: 7 Deleted: 0 Skipped: 0 Warnings: 0 mysql> load data infile 'd:ab' replace into table test1 FIELDS TERMINATED by ',' LINES TERMINATED by ';'; Query OK, 2 rows affected (0.09 sec) Records: 2 Deleted: 0 Skipped: 0 Warnings: 0 mysql> load data infile 'd:e.txt' replace into table test1 FIELDS TERMINATED by ',' LINES TERMINATED by ';' ignore 2 Query OK, 0 rows affected (0.00 sec) Records: 0 Deleted: 0 Skipped: 0 Warnings: 0
outfile
mysql> select * into outfile 'd:out1.txt' from test1; Query OK, 23 rows affected (0.00 sec) mysql> select * into outfile 'd:out2.txt' FIELDS TERMINATED by ',' from test1 -> ; Query OK, 23 rows affected (0.00 sec)
mysql> select * into outfile 'd:out3.txt' FIELDS TERMINATED by ',' lines terminated by ';' from test1 -> ; Query OK, 23 rows affected (0.02 sec)
感謝各位的閱讀!關于“MYSQL如何使用infile/outfile”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。