问题描述
我有一个MySQL更新脚本,我想从命令行运行,但我想能够传递一个阶段域变量到脚本。
我知道这不会工作,但它是我可以描述我想做的最好的方法:
$ -uroloc -hlocalhost mydatabase --executeSET @domain ='mydomain.dev'< ./sql/update_domain.sql
在脚本中,我使用@domain变量,使用如下命令更新配置表中的一些配置变量:
UPDATE my_cfg SET value = @domain WHERE name ='DOMAIN ';
基本上我想在update_domain.sql文件中的SET @domain前面加上
$在BATCH文件中: / p>
mysql -eset @ domain = PARAMVALUE; source ./sql/update_domain.sql
在您的SQL档案中:
UPDATE my_cfg SET value = @domain WHERE name ='DOMAIN';
I have a MySQL update script I'd like to run from the command line, but I want to be able to pass a stage domain variable to the script.
I know this won't work, but it's the best way I can describe what I'm trying to do:
$ -uroot -hlocalhost mydatabase --execute "SET @domain = 'mydomain.dev' " < ./sql/update_domain.sql
Inside the script, I'm using the @domain variable, to update some configuration variables in a config table, using commands like this:
UPDATE my_cfg SET value = @domain WHERE name = 'DOMAIN';
Basically I want to prefix the SET @domain on the update_domain.sql file.
Any ideas how I can rectify my approach?
In your BATCH File :
mysql -e "set @domain=PARAMVALUE;source ./sql/update_domain.sql"
And in you SQL file :
UPDATE my_cfg SET value = @domain WHERE name = 'DOMAIN';
这篇关于将MySQL变量从命令行传递到脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!