This article discusses using the SELECT INTO OUTFILE statement in MySQL.
The SELECT INTO OUTFILE statement writes the results of a query to a file. You can also specify custom column and row terminators to format the output.
SELECT INTO OUTFILE statements are supported on all unmanaged hosting packages, where you have complete control over the environment, including MySQL user privileges and configuration.
Shared and reseller hosting packages, however, do not allow you to run SELECT INTO OUTFILE statements. For security reasons, users are not granted the FILE privilege, which is necessary to run SELECT INTO OUTFILE statements.
If your hosting package does not allow you to run SELECT INTO OUTFILE statements, you can still create files based on MySQL queries. To do this, simply redirect the SQL query output to a file from the command line. The following example demonstrates how to do this:
echo "sql_query;" | mysql --user=mysql_username --password=mysql_password mysql_database > /home/username/query.txt
In this example, query output is redirected to the query.txt file. Make sure you use the following parameters correctly in your own commands:
You can modify these values, including the path for the output file, to meet your own requirements.
For more information about SELECT INTO OUTFILE, please see the official documentation at https://mariadb.com/kb/en/select-into-outfile.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.