使用filename中的变量在shell上导入MySQL转储

时间:2014-12-18 18:27:06

标签: mysql bash shell vagrant

在Dev Env中,我使用db-name作为用户名和密码。在我的Vagrant bootstrap.sh中,我有以下几行:

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

在流浪汉上我得到错误

==> 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
...

使用电子邮件等等待导入表的列。我解释这个,以便我的sql文件作为bash脚本执行,而不是通过管道传输给mysql。如果我在流浪汉完成后通过ssh运行相同的命令,一切正常。我的错误在哪里?

1 个答案:

答案 0 :(得分:0)

让我做了半天的事情,在发布问题后5分钟就发现了我:

mysqldump使用反引号转义列名。在bootstrap.sh中使用时,这些反引号由linux的反引号运算符解释。

解决方案是使用

执行mysqldump
--skip-quote-names 

参数

相关问题