Select... Into OUTFILE Error 1 (hy000) at line 1: Can't create/write to file...

Source: Internet
Author: User
Tags mysql command line

MySQL SELECT statement allowed us to pipe the query result in to a file via Select... into OUTFILE. It work just fine for me most of the time, until recently I hit this error:

Error 1 (hy000) at line 1: Can't create/write to file '\ home \ myuser \ my_output_file.txt' (errcode: 2) mV: cannot stat '/home/myuser/my_output_file.txt': no such file or directory

The first thing come to my mind is the problem of File Permission, So I grant 777 permission to my output directory. But the problem still exist.

Then I check the MySQL username I use, and found that it was granted with File Permission correctly.

Then I start to Google on this error code, and most of the search result point to Similars causes.

So I read again
Documentation of MySQL, and I found this:

The select... into OUTFILE 'file _ name' form of select writes the selected rows to a file. the file is created on the server host, so you must have the file privilege to use this syntax.

And the keyword is "server host". I made wrong assumption that it will write file to the server that execute the Select... into OUTFILE.

And the workaround is simple, just change my SELECT statement by remove the OUTFILE portion. and pipe the query to file from the MySQL Command Line

Mysql-u myuser-ppassword-H remotehost mydb <myquery. SQL> my_output_file.txt

Reading documentation is bored but important

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.