简体   繁体   中英

how to clear/hide mysql errors from command prompt

I am using mysql command responses in my script

When database connection was lost, MySQL would fail to response queries & at that time MySQL error will be shown in command prompt like

mysql -u root TEST -e "show tables"
ERROR 2003 (HY000): Can't connect to MySQL server on 'X.X.X.X' (111)

I am in-need to hide that MySQL error from command prompt when i execute the query.

Redirect standard error, just like you would any other command if you don't want to see errors.

mysql -u root TEST -e "show tables" 2>/dev/null

If you also want to hide the normal output, redirect standard output as well:

mysql -u root TEST -e "show tables" >/dev/null 2>&1

You can try "\\! clear" , it will execute clear shell command."\\!" is used to execute shell command.

mysql> \! clear

in *nix it will clear your command prompt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM