简体   繁体   中英

Importing MySQL dump on shell with variable in filename

In a Dev Env I use the db-name for both username and password. In my Vagrant bootstrap.sh I have following lines:

dbname=master
...
/usr/bin/mysql -u ${dbname} -p${dbname} ${dbname} < /vagrant/vagrant/tmp/latest-${dbname}.sql

On vagrant up I get the error

==> default: /tmp/vagrant-shell: line 273: id: command not found
==> default: /tmp/vagrant-shell: line 273: email: command not found
==> default: /tmp/vagrant-shell: line 273: phone: command not found
...

with email etc. beeing columns of a to-be-imported table. I interpret this such that my sql file is beeing executed as bash script instead of beeing piped to mysql. If I run the same command via ssh after vagrant up finished, everything works. Where´s my error?

Making me thing half a day, it hit me 5 minutes after posting the question:

mysqldump escapes column names with backticks. When used in the bootstrap.sh, those backticks are interpreted by linux' backtick operator.

Solution is to execute mysqldump with the

--skip-quote-names 

parameter

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