Connecting Tech Pros Worldwide Help | Site Map

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

Member
 
Join Date: Nov 2008
Posts: 35
#1: Jan 7 '09
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
micmast's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Belgium
Posts: 136
#2: Jan 7 '09

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


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
Member
 
Join Date: Nov 2008
Posts: 35
#3: Jan 7 '09

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


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
Reply


Similar Unix / Linux / BSD bytes