1

I know there're tons similar question but somehow I can't get it right.

When run this command, my "dump.sql" produced desired result

mysqldump -uuser -ppassword --comments --single-transaction --quick mydb desired_table | gzip >dump.sql.gz

This is the first line of dump.sql

-- MySQL dump 10.13  Distrib 8.0.21, for Linux (x86_64)

But with this command:

nohup mysqldump -uuser -ppassword --comments --single-transaction --quick mydb desired_table | gzip >dump.sql.gz 2>/dev/null &

This is the first line of dump.sql:

mysqldump: [Warning] Using a password on the command line interface can be insecure.

Which will cause error when import the dump file. How? From what I understand, "2>" means redirect error. If I change to this command, nothing in the "dump.log":

nohup mysqldump -uuser -ppassword --comments --single-transaction --quick mydb desired_table | gzip >dump.sql.gz 2>dump.log &
9
  • It's a warning, not an error. You expected it to be written to stderr, but you've established it's written to stdout. Commented Nov 22, 2022 at 12:11
  • @ElliottFrisch I dont really understand. Please enlighten. Do you mean "2" only referring to error but not warning? Is there any dedicated number represent warning? Commented Nov 22, 2022 at 13:52
  • 1
    There is not. 2 is stderr. 1 is stdout. Commented Nov 22, 2022 at 13:56
  • 1
    nohup mysqldump -uuser -ppassword --comments --single-transaction --quick mydb desired_table | grep -v Warning | gzip >dump.sql.gz 2>/dev/null & will just ignore any warnings. Commented Nov 22, 2022 at 14:10
  • 1
    It literally just ignores any warnings. This is not generally recommended. Commented Nov 22, 2022 at 14:39

1 Answer 1

2

To redirect the stderr of the mysqldump command before sending it to gzip, do that before the pipe.

nohup mysqldump -uuser -ppassword --comments --single-transaction \
   --quick mydb desired_table 2>/dev/null | gzip >dump.sql.gz  &

This is not related to your stderr redirection question, but I would also recommend using an options file instead of putting user and password on the command line.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you its working. I'm getting better of understanding after ur sample. But I wonder why with ur code, when I execute, the terminal back to prompt (as if the process has done but actually still running). Compare to my original code where the terminal display " nohup: ignoring input and redirecting stderr to stdout" and I have to CTRL+C to get the prompt
The & at the end of the command line puts the whole process into the background. Here's a good article covering the basics of job control in the bash shell: digitalocean.com/community/tutorials/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.