I'm trying to write a bash script that will create a database using a variable for the new name but not having any luck with the syntax. I know almost next to nothing about bash. Keeps telling me there's a syntax error at line 1 after I enter the db password.
setup.sh
#!/bin/bash
db="mytest"
scl enable rh-mariadb 'mysql -u user -p -e "set @dbname=$db; \. setup_db.sql"'
setup_db.sql
SET @query = CONCAT('CREATE DATABASE `', @dbname, '`');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREAPRE stmt;
If I hardcode the db name where I have $db in the bash then I receive this error:
Unknown column 'mytest' in 'field list'
CREATE DATABASEstatement. You probably have some other statement in yoursetup_db.sqlfile that is malformed.