how can i redirect Mysql table output to file in Linux?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xtremebass
    New Member
    • Nov 2008
    • 38

    how can i redirect Mysql table output to file in Linux?

    Hi Bytes, in Linux , is it possible to redirect Mysql table output to a file in Linux.

    i tried it, shows error , but output has displayed in linux prompt when no redirection of file has given(say select * from tablename) but when i am trying redirect output to file in Linux it shows error? can you tell me suggestion for this issue.

    code i used :
    <code>
    #!bin/sh
    password=xyzbac
    mysql -u root -p$password -h 192.168.1.8 << y
    use sys;
    select memory from sysprofile >> newf1
    quit
    y

    </code>

    got error:

    ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>> newf1
    quit' at line 1
    Last edited by Frinavale; Jan 9 '09, 10:04 PM. Reason: Moved to Unix Answers from Insights
  • micmast
    New Member
    • Mar 2008
    • 144

    #2
    What happens if you try this:

    #!bin/sh
    password=xyzbac
    mysql -u root -p$password -h 192.168.1.8 << y
    use sys;
    echo `select memory from sysprofile` >> newf1
    quit
    y

    Comment

    • xtremebass
      New Member
      • Nov 2008
      • 38

      #3
      Error i got after changes that you have suggested:

      tesst1.sh: command substitution: line 1: syntax error near unexpected token `from'
      tesst1.sh: command substitution: line 1: `select memory from sysprofile'
      ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'echo >> newf1
      quit
      y' at line 1

      Comment

      Working...