SELECT into outfile 備份數據庫數據
select email into outfile "test.txt" from email;
select substring(boss,0,2),addr from guest;
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE “/opt/abc.txt" INTO TABLE table_name -www.2cto.com-
FIELDS TERMINATED BY ',' (column1, column2,colum3);
mysql> SELECT * FROM table1 INTO OUTFILE 'data.txt'
FIELDS TERMINATED BY ','
FROM ...
為了將由逗號分隔的文件讀回來,正確的語句將是:
mysql> LOAD DATA INFILE 'data.txt' INTO TABLE table2
FIELDS TERMINATED BY ','; -www.2cto.com-
相反,如果你試圖用下面顯示的語句讀取文件,它不會工作,因為它命令LOAD DATA INFILE在字段之間
尋找定位符:
mysql> LOAD DATA INFILE 'data.txt' INTO TABLE table2
FIELDS TERMINATED BY '\t';
可能的結果是每個輸入行將被解釋為單個的字段。
LOAD DATA INFILE能被用來讀取從外部來源獲得的文件。例如,以dBASE格式的文件將有由逗號分隔並用
雙引號包圍的字段。如果文件中的行由換行符終止,下面顯示的命令說明你將用來裝載文件的字段和行
處理選項:
mysql> LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n'; -www.2cto.com-
任何字段或行處理選項可以指定一個空字符串('')。如果不是空,FIELDS [OPTIONALLY] ENCLOSED BY和
FIELDS ESCAPED BY值必須是一個單個字符。FIELDS TERMINATED BY和LINES TERMINATED BY值可以是超
過一個字符。例如,寫入由回車換行符對(CR+LF)終止的行,或讀取包含這樣行的一個文件,指定一個
LINES TERMINATED BY '\r \n'子句。 -www.2cto.com-
FIELDS [OPTIONALLY] ENCLOSED BY控制字段的包圍字符。對於輸出 (SELECT ... INTO OUTFILE),如果
你省略OPTIONALLY,所有的字段由ENCLOSED BY字符包圍。對於這樣的輸出的一個例子(使用一個逗號作
為字段分隔符)顯示在下面:
"1","a string","100.20"
"2","a string containing a , comma","102.20"
"3","a string containing a \" quote","102.20"
"4","a string containing a \", quote and comma","102.20"
=================
insert into tabl(id,email) select id, email from guest;
作者 huimai