Grammar:
The SELECT ... Into OUTFILE ' file_name ' [options] form of SELECT writes the selected rows to a file.
Example:
Select * fromStudents intoOutFile'Test/users.csv'Fields terminated by ','Optionally enclosed by '"' --Fields separated by commas and enclosed within double quotation marksLines terminated by '\ r \ n'
Attention:
1, the syntax can only be executed on the MySQL server;
2. The location of the data file is related to the value specified by file_name.
Where the folder needs to be created manually and the file cannot be a file that already exists
Reason:/Don't understand Wow ~
file_nameCannot be a existing file, which among other things prevents files such as and /etc/passwd database tables from being destroyed .
Additional Example Instructions:
Current Library:
Select DATABASE -- Mydemo
Data File Save location:
Select @ @datadir; -- D:\Programs\MySQL\Data\ -- Show variables like ' DataDir '
Example:
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\
Where error: Can ' t create/write to file ' D:\Programs\MySQL\Data\test\users.csv ' (errcode:2)
Based on the error number Errcode, locate the error cause: You need to manually create the folder 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\
Import external files
Load ' Test/users.csv ' REPLACE into Table by', ' by'" ' by'\ r \ n'
Reference:
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
Note-mysql Export Query results