1

I would like to know is there any way to log the mysql query error which prints on screen.

Example:

mysql -u$UserName -p$Password -D $DBName -e "ALTER TABLE  collect ADD  path VARCHAR( 250 ) NOT NULL AFTER  my_path "

This will return duplicate column if it exists... I would like to log this error on a text file, which will help in my automation.

3

1 Answer 1

4

Redirect the standard error stream of mysql to a file:

mysql ...options... 2>error_log.txt

Furthermore, make sure that you double quote the variable $UserName (and the others) so that spaces and characters that may be special to the shell are preserved.

See the answers to the following question about how to avoid using a password on the command line for MySQL: Use a password in shell-script

0

Not the answer you're looking for? Browse other questions tagged .