0

I am working on a script most of it works fine until it gets to line 27 of it. Which is where I have the script login to MySQL as root, create a new database and then exit MySQL.

echo "CREATE DATABASE databasename;exit;" | mysql -h localhost -u root -p --password=passwordhere

Am I calling the command correctly because it fails on this line every time and how would I fix it?

OS is Ubuntu 10.10 32 bit.

Error: ./install: line 27:  mysql: command not found

4
  • 3
    "it fails on this line every time" How exactly does it fail? Does it give an error message? What is the error message? Commented Feb 27, 2012 at 21:17
  • 1
    Maybe the databasename is a reserved word? Maybe the database exists already? Please post your exact error message. Commented Feb 27, 2012 at 21:20
  • It was something like MySQL command not found line 27 Commented Feb 27, 2012 at 22:45
  • Exact error: ./install: line 27: mysql: command not found Commented Feb 27, 2012 at 22:52

2 Answers 2

1

I think you don't need to type "exit", when you pass the SQL commands through stdin - just use

echo "CREATE DATABASE databasename" | mysql -h localhost -u root -p --password=passwordhere

HTH,

good luck,

a.

Sign up to request clarification or add additional context in comments.

3 Comments

So once it moves on to the next command it will drop out of SQL mode?
Still get error: Exact error: ./install: line 27: mysql: command not found
The 'mysql: command not found' means your bash doesn't found mysql - but if it's true, I don't understand why did you get the original error message? (Is this question was modified?)
0

How about doing this:

$ mysql -h localhost -u root --password=password -e "CREATE DATABASE databasename;"

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.