Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OUTPUT RESULTS TO A FILE 1

Status
Not open for further replies.

PrgrmsAll

Programmer
Apr 8, 2003
180
US
Is there any way in MySQL to direct output from a query to a textfile? I did a search on this and found the following code snippet here in tek-tips, however, I have been unable to make it work:

SELECT * INTO OUTFILE MyOutput.TXT
FIELDS TERMINATED BY ","
FROM MyFile
WHERE Condition = MyCondition

Any thoughts/advice would be appreciated. Thank you in advance!
 
What happens when you run that? Error messages? Unexpected values in the text file?
 
Replies with error message, complaining about syntax 'near' MyOutput.txt. Should this be a literal string?

 
Yeah...it should be something like:

Code:
SELECT * INTO OUTFILE 'MyOutput.TXT'
    FIELDS TERMINATED BY ","
    FROM MyFile
    WHERE Condition = MyCondition

that will dump the file into the current directory of the mysql server. if you want it elsewhere, it needs to be either the full or relative path as well.
 
Thanks! I am closer but now I am getting a "ERROR 1045 (28000): Access denied for user 'ctedbadmin'@'%' (using password: YES)" message.
 
according to the documentation, the user must have the FILE privilege to use this syntax.
 
from the command line:
Code:
GRANT FILE ON databasename.* TO ctedbadmin@'%';
or if you have a password for ctedbadmin, then you could type:
Code:
GRANT FILE ON databasename.* TO ctedbadmin@'%' IDENTIFIED BY 'password';
 
What I actually ended up doing was downloading the MyODBC drivers from mysql.com. With the odbc drivers installed, I was able to connect to MySQL from a dts package on SQLServer and import that data directly into my database. This is ultimately what I wanted to do, I guess I was making it more difficult for myself. Thank you for your posts, though, they were much appreciated.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top