Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Im making a script where I connect to a database, look for a value and then if that value returned something then I will do something else.

ip=$("variable is defined here")

Then I connect to the MYSQL database using:

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot --password=*

However, this takes me to another prompt, and I need to run another command from that, I can't get it to work.

I tried this:

/Applications/MAMP/Library/bin/mysql "MYSQL argumens;";

and just:

MYSQL arguments;

None of these work and I have to pass a variable to it, what can I do now?

share|improve this question
    
You might find the DBA SE useful. –  mdpc Nov 23 '14 at 20:05

2 Answers 2

up vote 2 down vote accepted

You can do something like this:

#! bin/bash
selectvar="SELECT * FROM test;"

mysql --user=root --password=mypass database << eof 
$selectvar
eof
share|improve this answer
    
Thanks dude! Really helped me. –  DisplayName Nov 23 '14 at 17:41

To execute statements from the command line without an interactive prompt, use the -e option:

mysql mydb -e 'select * from foo'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.