Note-mysql Export Query results

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.