mysql -hxx -uxx -pxx -e "query statement" db > file
例如:
mysql -h127.0.0.1 -uroot -p000000 -e"select * from a" test > 1.txt
host ip user password query statement database filename
這樣會輸出列名資訊,如果不想輸出列名資訊:
mysql -h127.0.0.1 -uroot -p000000 -n -e"select * from a" test > 1.txt
host ip user password query statement database filename 或
mysql -h*** -uxx -pxx
select * from table into outfile '***.txt';
例如:
mysql -h127.0.0.1 -uroot -p000000
select * from a into outfile '1.txt';
兩種方法效果一樣的
第二種方式的mysql文件:
select [select options go here] into filename
export_options
from table_references [additional select options go here]
例如:
mysql -h127.0.0.1 -uroot -p000000
select * from a into outfile "1.txt" fields terminated by '\t' lines terminated by '\r\n'
第一種方法和第二種方法的結合:使用 mysql -e執行匯出到檔案的sql語句
mysql -hxx -uxx -pxx -e "query statement" db
例如:
mysql -h127.0.0.1 -uroot -p000000 -e"select * from a into outfile '1.txt' fields terminated by ',' lines terminated by '\r\n'" test
如果不想輸出列名資訊:
mysql -h127.0.0.1 -uroot -p000000 -n -e"select * from a into outfile '1.txt' fields terminated by ',' lines terminated by '\r\n'" test
預設情況下, mysql -e匯出的檔案,列是用"\t"分隔,行是用"\r\n"分隔(
dos),行是用"\n"分隔(unix
追加一種方式:
select col002,col005,col004,col008 into outfile 'e:/mysql/i0812.txt' fields terminated by '|' lines terminated by '\r\n' from a where col003 in (select col001 from qdbm) order by col005;
mysql 匯出select結果到文字的幾種方式
mysql hxx uxx pxx e query statement db file 例如 mysql h127.0.0.1 uroot p000000 e select from a test 1.txt host ip user password query statement databas...
mysql計算的結果匯出 mysql 匯出查詢結果
select from my table into outfile tmp abc.xls 然後就是ftp把檔案弄回本地了。我的是程式自動放到c 下 另外,還有一種匯出的方式,相較於上者而言,這種可以對已經存在的檔案直接覆蓋。使用outfile的方法 mysql select 1 into outf...
筆記 mysql 匯出查詢結果
語法 the select into outfile file name options form of select writes the selected rows to a file.示例 select from students into outfile test users.csv fie...