This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16353|Reply: 0

[Source] MySQL exports the query results to a file

[Copy link]
Posted on 2/7/2021 10:01:03 AM | | | |
MySQL uses mysqldump to export data with conditions
https://www.itsvse.com/thread-7498-1-1.html

mysqldump imports and exports database summaries
https://www.itsvse.com/thread-4353-1-1.html

MySQL database backup and export
https://www.itsvse.com/thread-4004-1-1.html
Scenario: Sometimes, we need to export the query data to a hard disk file so that we can use it for other purposes.

Method 1

Execute in the mysql command line environment: sql statement + INTO OUTFILE + file path/file name + encoding method (optional)

For example:

When exporting, we may not have permission to write to a disk directory:

ERROR 1 (HY000): Can't create/write to file '/root/itsvse.sql' (Errcode: 13 - Permission denied)


There may be Chinese garbled characters in the generated file, which can be +CHARACTER SET gbk (utf8, etc.) after the statement.

For example:




Method 2

Queries are automatically written to the file:



All subsequent query results are automatically written to /tmp/test.txt' and overwritten before and after



The query results are no longer displayed in the box.





Previous:SQL Server sets the transaction isolation level
Next:EF Core Series (3) Entity Frame Shadow Attributes [Reprint]
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com