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?
This works for me:
...calling with system() from Capistrano.
In your BATCH File :
And in you SQL file :
you can do that with
sed
like this:or update.sql has
UPDATE
: