Mysql命令下導出select查詢數據之 select ... into outfile方法

Mysql平常使用中常常遇到將select查詢的數據導出到本地目錄的狀況,以便數據備份、分析等。mysql

接下來將介紹Mysql終端下使用 select ... into outfile 語句導出數據方法sql

命令:編碼

mysql> SELECT * FROM passwd INTO OUTFILE '/tmp/runoob.txt'
    -> FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    -> LINES TERMINATED BY '\n';

/**
參數說明:
 用來對字段值之間進行分割,
 用來對字段值進行包裹,
FIELDS  LINES TERMINATED BY 用來對每行結束指定換行符
*/FIELDS TERMINATED BYFIELDS [OPTIONALLY] ENCLOSED BY

舉例spa

mysql> SELECT * from student into outfile '/home/homework/shenwenzhe/student.txt'; 

 

另外:code

介紹下into outfile命令的相反命令:load data infile  數據導入,命令以下:blog

load data infile "/home/homework/shenwenzhe/student.txt" into table student;

 注意點:若是導出時用到了FIELDS TERMINATED BY ',' ,OPTIONALLY ENCLOSED BY '"', LINES TERMINATED BY '\n'等語句,那麼load時也要加上一樣的分隔限制語句,而且要注意數據編碼問題。table

相關文章
相關標籤/搜索