0

I want to try and import a database from an SQL file. I want to supply the argument for the --defaults-extra-file parameter by echoing a config file and pipe the output to the command.

This command:

echo -e "[client]\nuser=user\npassword='mypass'\nhost=10.20.30.14\n" | mysql --defaults-extra-file=/dev/stdin db-1 < db-2.sql

Return this error:

mysql: [ERROR] Found option without preceding group in config file /dev/stdin at line 1.
mysql: [ERROR] Fatal error in defaults handling. Program aborted!

But I do have its group defined. I have tried these groups [client], [mysql] and [mysqld]

I also tried the --defaults-file parameter.


I do not have this same problem for the mysqldump command. Below command works fine:

echo -e "[client]\nuser=user\npassword='mypass'\nhost=10.20.30.14\n" | mysqldump --defaults-file=/dev/stdin --add-drop-table db2 -N --column-statistics=0 > db-2.sql

1 Answer 1

0

mysql (or any other command) cannot read two separate files via its stdin. The stdin is one file. Your first command is basically:

echo -e "…\n" | mysql … < db-2.sql

It's like:

echo foo | cat - < /etc/fstab

Try it. < "wins" over | in setting up where the stdin of cat comes from.

Your second command does not contain <; it contains > db-2.sql which redirects stdout. In this case | works as you expect.

1
  • That makes sense. I have split up the command to create the config file first and then use it as input. I was hoping to combine it in 1 line. Thank you! Commented Oct 21, 2022 at 6:49

You must log in to answer this question.

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