標籤:rect hive code min ota mysql 匯出 ever 額外 筆記
文法:
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‘ fields terminated by ‘,‘ optionally enclosed by ‘"‘ -- fields separated by commas and enclosed within double quotation marks lines terminated by ‘\r\n‘
注意:
1、該文法只能在MYSQL伺服器上執行;
2、資料檔案的儲存位置與file_name指定的值相關。
其中,檔案夾需要手動建立,檔案不能為已存在的檔案
原因: /不懂哇~
file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed.
額外樣本說明:
當前庫:
select DATABASE(); -- mydemo
資料檔案儲存位置:
select @@datadir; -- D:\Programs\MySQL\Data\-- show variables like ‘datadir‘
樣本:
1、”fname” - %datadir%/<db_name>
file_name=‘users.csv‘
file_path= D:\Programs\MySQL\data\mydemo\
2、”/fname” – rootd_%datadir%/
file_name=‘/users.csv‘
file_path=D:\
3、”folder_name/fname” – %datadir%/folder_name
file_name=‘test/users.csv‘
file_path= D:\Programs\MySQL\data\test\
其中,此處報錯:Can‘t create/write to file ‘D:\Programs\MySQL\Data\test\users.csv‘ (Errcode: 2)
根據錯誤編號Errcode,定位錯誤原因:需要手動建立檔案夾 test
> perror 2OS error code 2: No such file or directory
4、”/folder_name /fname” – rootd_%datadir%/folder_name
file_name=‘/test/users.csv‘
file_path= D:\test\
匯入外部檔案
load data infile ‘test/users.csv‘ REPLACE into table studentsfields terminated by ‘,‘ optionally enclosed by ‘"‘lines terminated by ‘\r\n‘
參考:
https://dev.mysql.com/doc/refman/5.7/en/select-into.html
https://dev.mysql.com/doc/refman/5.7/en/load-data.html
http://www.mysqltutorial.org/import-csv-file-mysql-table/
http://www.cnblogs.com/zeroone/archive/2013/01/12/2857388.html
http://www.cnblogs.com/ahudyan-forever/p/5817847.html
筆記-mysql 匯出查詢結果