MySQL查詢結果匯出檔案

2021-10-04 22:03:33 字數 876 閱讀 8099

「翅低白雁飛仍重,舌澀黃鸝語未成」

很多時候,我們需要將資料庫的查詢結果自動儲存到檔案,這樣就免得手動複製貼上了。

select * from tablename into outfile "d:\\program\\mysql\\mysql-5.7.18-winx64\\data.txt"

;

說明:以上語法為:將tablename 表的內容匯出到「d:\program\mysql\mysql-5.7.18-winx64\」目錄下的data.txt檔案。

如果以上語句在執行時出現下面錯誤

the mysql server is running with the --secure-file-priv option so it cannot execute this statement

首先檢查匯出功能是否開啟,show variables like "secure_file_priv";

如果該值是null,則需要在mysql的配置檔案中my.ini新增匯出的屬性:

secure_file_priv=

'd:\program\mysql\mysql-5.7.18-winx64'

然後重啟資料庫即可。

2. 如果設定匯出檔案的目錄,還是報上面的錯,則需要檢視匯出檔案的sql語句中的目錄是否正確,應該和配置檔案的路徑一致,因為有可能在其他目錄,mysql沒有許可權去建檔案。此時只需要修改匯出的目錄到配置目錄即可。

MYSQL匯出查詢結果到檔案

select order id product name qty from orders into outfile data data.txt select order id product name qty from orders into outfile tmp orders.csv field...

mysql查詢結果匯出到檔案

方法一 直接執行命令 mysql select count 1 fromtable into outfile tmp test.xls query ok,31 rows affected 0.00 sec 在目錄 tmp 下會產生檔案test.xls 遇到的問題 mysql select count...

mysql查詢結果匯出到檔案

環境 mysql 進入mysql shell mysql u username password password database database然後輸入匯出查詢結果命令 select from table1 into outfile data test1.txt 報錯error 1045 28...