Feed on

let’s say your mysql user doesn’t have write access to your machine and using the INTO OUTFILE syntax is throwing errors:

ERROR 1045 (28000): Access denied for user

you can get around these problems by submitting your mysql query  directly from the command line and  piping the output to a text file like so:

>> echo “SELECT foo FROM bar” | mysql -h sql.server -uUserName -pPassword Database > foo.bar

Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

2 Responses to “write output mysql command to text file”

  1. on 09 Sep 2011 at 9:43 am shweta

    Hi All,

    How do i print the output of “mysql” command to the output.txt file??

    for ex:
    if this is the command :
    mysql -h localhost -u root -proot <

    if the backup file is corrupted, it will give the error as below in the
    command prompt itself :
    ERROR 1064 (42000) at line 27: You have an error in your SQL syntax;
    check the
    anual that corresponds to your MySQL server version for the right syntax
    to use
    near 'hhhgh
    DROP TABLE IF EXISTS `admin_action_icon`' at line 1

    The same (error statements)if i wants to put it in some text file, how do i do that?? please
    can someone help me in this??


  2. on 03 Jan 2012 at 4:55 am Gaurav Gupta

    Simpler: mysql YourDatabase -uroot -prootp -e “select * from table”

Did I get this wrong? Let me know!

Trackback URI | Comments RSS