6

Is it possible to make a sql script use a variable defined externally?

E.g. I have the following script:

UPDATE mytable
SET    valid = 0
WHERE  valid = 1

which I have to run through mysql command line several times, each with a different table name.

I would like something like:

SET table_name=foo
mysql -uuser -ppassword < myscript.sql

is it possible?

2
  • it would be easy if you use some languages ! Commented Apr 22, 2011 at 13:02
  • I was trying to do that in pure mysql/DOS mode... :( Commented Apr 22, 2011 at 15:24

1 Answer 1

5

Skirting around the environment variables, why not:

sed 's/mytable/foo/' myscript.sql | mysql -uuser -ppassword
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a similar program in Windows/DOS?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.