简体   繁体   中英

Creating a MySQL Database Using a Variable in a BASH Script

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM