2

I'm trying to create a MySQL database using a variable in a BASH script. Here is the code giving me trouble: database="mysql --verbose --user=root --password --execute="create database foo"" When run it fails with an option listing. I'm sure the issue is with the use of quotes after the execute option but I can't figure out how to get it to work.

1
  • use different quotes: database="... --execute='create database foo'" Commented Sep 26, 2012 at 20:44

2 Answers 2

1

What is the point of setting the database variable?

mysql --verbose --user=root --password --execute="create database foo"

Should work just fine for creating the database foo

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

Comments

0

Try this:

#!/bin/sh
mysql --verbose --user=root --password --execute="create database $1"

save it in your bashscript folder and run it like:

nameofbashscript mydatabasename

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.