Jump to content

Archived

This topic is now archived and is closed to further replies.

NevadaSam

Output DB to text file

Recommended Posts

I want to dump the contents of a table from my database into a text file. My logon (host, username, password) are all correct. And my query syntax is good.
[quote]SELECT * INTO OUTFILE 'books.txt'
FIELDS TERMINATED BY '|'
FROM books[/quote]
But I get this error when I run it:[code]Error 1045: Access denied for user 'user'@'localhost' (using password: YES)[/code]
I was hoping that it would write the txt file to the directory from where I was running the query. But I am thinking that it is trying to write it to the MySQL server which, of course, I don't have permission to do.

How can I dump this?

Sam



Share this post


Link to post
Share on other sites
I'm pretty sure you need the LOCAL modifier so that you're not writing to the server directory.

Share this post


Link to post
Share on other sites

I tried many different variations of the file location modifier ("/public_html/save.txt" and more) but I believe it is a privilege issue. I learn more about the SELECT INTO OUTFILE command since my last post. It seems that the FILE privilege is normally not granted because of security reasons. This from my text: [quote][b][u]The FILE privilege[/u].[/b] This enables a user to access files on the server machine with the same privileges as the MySQL server process. This privilege is useful for executing the LOAD DATA INFILE and SELECT INTO OUTFILE statements that read from and write to server-side files. This privilege, however, can be abused as a backdoor around operating systems security and thus should be granted sparingly.[/quote]

I can do the LOAD DATA INFILE on most hosting services. So when I learn more about PHP I will write a script that will SELECT all the data from a table and then I will output it to a text file that way. Thanks for taking time to read my posts.

Sam

Share this post


Link to post
Share on other sites
I didn't realize that the file had to be written on the server host, and hence would require FILE permissions that are generally not granted for security reasons.  But yes, you might as well just roll-your-own export script.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.