how to redirect a error returned from mysql syntax

Following is a shell file in linux. I am executing a mysql query from the file. I want the error from the execution to be redirected to a file.
The present redirection does not redirect the mysql errors.

#!/bin/sh
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 95 10

mysql -u${MYSQL_ROOT_USER} -p${MYSQL_ROOT_PASSWORD} -e "show tables in omcr;" 1>/dev/null 2>&1
   isTables=$?
   if [ $isTables -ne 0 ] ; then
      dexist=0
   fi
pvinodpAsked:
Who is Participating?
 
AwesomeMachineConnect With a Mentor Commented:
Ok, if you want to see the program output, but not the errors, you want to change that to

omcr;" &2>~/errors.txt

If you don't want program output, but you do want error redirection
omcr;" &1> /dev/null &2>~errors.txt
0
 
omarfaridCommented:
it is redirecting to /dev/null which is pasically to ignore or trash the output and errors. You may do it like

mysql -u${MYSQL_ROOT_USER} -p${MYSQL_ROOT_PASSWORD} -e "show tables in omcr;" 1>/dev/null 2> /path/to/mysql_errors
0
 
pvinodpAuthor Commented:
it does not work.. i still get error prompted on to my screen
0
 
point_pleasantConnect With a Mentor Commented:
possibly the problem is with mysql try inside mysql:

mysql> pager '/dev/null'
0
 
pvinodpAuthor Commented:
I have managed to rewrite the sql query which will not generate a error. thanks anyways
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.