简体   繁体   中英

Suppress warning when sourcing sql file back to mysql database

/opt/mysql/bin/mysqldump -udbuser -pAdmin@123 -h192.167.93.44 -P32083 --single-transaction --set-gtid-purged=OFF --databases mohwscdrdb mohwsecsdb moresourcelifecycledb moorderdb movdcservicedb > ./backup.sql 2>&1 | grep -v "Warning"

That was run as I thought, without "Warnning: using password.." blablabla.

But when I execute:

/opt/mysql/bin/mysql -udbuser -pAdmin@123 -h192.167.93.44 -P32083 < ./backup.sql 2>&1 | grep -v "Warning"

in order to source back the sql file without warnning, it fails, saying:

/' at line 1

I think it was because I have two different redirect directions ( < and > ) in one line, but how to fix this?

2>&1 ties both file descriptors together. You only want to grep on stderr so by using '|&' only the stderr goes to grep.

So on dumping:

/opt/mysql/bin/mysqldump ... movdcservicedb > ./backup.sql |& grep -v "Warning"
/opt/mysql/bin/mysqldump -udbuser -pAdmin@123 **> ./backup.sql** 2>&1 | grep -v "Warning"

change the order, moving the redirecting part to the end of the command, will make the thing done.

/opt/mysql/bin/mysqldump -udbuser -pAdmin@123 2>&1 | grep -v "Warning" **> ./backup.sql**

by the way, importing sql should keep the < ./backup.sql in the middle of the command.

/opt/mysql/bin/mysql -udbuser -pAdmin@123 < ./backup.sql 2>&1 | grep -v "Warning"

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