select結果匯出為excel
阿新 • • 發佈:2019-01-07
(方式1)
在cmd中執行命令,格式如下:
mysql -hxx -uxx -pxx -e "query statement" dbName > file
-h:後面跟的是連結的host(主機)
-u:後面跟的是使用者名稱
-p:後面跟的是密碼
db:你要查詢的資料庫
file:你要寫入的檔案,絕對路徑
例:將 sql語句 select * from yhxxb 的查詢結果輸出到了 C:/Users/dellpc/Desktop/test.xlsx 這個檔案中。
mysql -h127.0.0.1 -uroot -proot -e "select * from yhxxb" test > C:/Users/dellpc/Desktop/test.xlsx
(方式2)
mysql -hxxx -uxx -pxx select * from table into outfile 'xxx.txt';
-h/-u/-p 的引數內容和上面一致, xxx.txt 是要輸出的檔案路徑及其名稱。
如:
-- 登入mysql mysql -h127.0.0.1 -uroot -proot -- 將查詢結果輸出到檔案中 select * from yhxxb into outfile C:/Users/dellpc/Desktop/test.xlsx