1

Is there a way/workaround/hack to pass an argument to a mysql script? Let's say I have a file name myqueries.sql which looks like this

SELECT * FROM FooBar where id = <arg>;

Then in mysql command, I know I can call this script by

mysql>source myqueries.sql

But is there a way to pass an argument here? Something like this:

mysql>source myqueries.sql 2

then I'd get the tuple with id = 2.

4
  • This seems to be a workaround. Commented Apr 4, 2013 at 23:57
  • I've looked at that before, but it wouldn't work in my case since I can't launch mysql myself. let's say once I exit mysql, i can't go back. Commented Apr 5, 2013 at 0:00
  • Are you on win or nix? Commented Apr 6, 2013 at 22:26
  • Unix, but I don't think it matters what OS I'm on, right? Commented Apr 11, 2013 at 19:19

1 Answer 1

1

myqueries.sql

SELECT * FROM FooBar where id = @arg;

on mysql

set @arg=2;
source myqueries.sql
Sign up to request clarification or add additional context in comments.

Comments

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.