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.

# 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
   if [ $isTables -ne 0 ] ; then
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
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
pvinodpAuthor Commented:
it does not work.. i still get error prompted on to my screen
point_pleasantConnect With a Mentor Commented:
possibly the problem is with mysql try inside mysql:

mysql> pager '/dev/null'
pvinodpAuthor Commented:
I have managed to rewrite the sql query which will not generate a error. thanks anyways
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.