I've tried using this code in a script but it just created what is inside the backtick. In this example, "echo "table-db"" was created in the database. It didn't create the name of the folder with the hyphen character in the query
hyph=`ls -l $DBDIR | egrep '^d' | grep '.-.' | awk '{print $9}'`
dbhype=($hyph)
for dbtry in ${!dbhype[*]}
do
mysql -u$dbUser -p$dbPass -e 'CREATE DATABASE IF NOT EXISTS `echo "table-db"` CHARACTER SET utf8 COLLATE utf8_general_ci';
echo "Database ${dbhype[$dbtry]} created."
done
This problem is characterized by an ORA-2083 'database name has illegal character '-'' error when using a fully qualified database link that has a hyphen in the domain name. This error only occurs when the database link is used in PL/SQL.
It is possible, but you don't want to do this because you'll have to enclose that table name in the proper quoting character for your database every single time.
Click on your MySQL server instance under the Server Administrator section of MySQL workbench to create a new database user and assign privileges to your new database. Click on Users and Privileges. Then click on Add Account. Enter a login name for the new user, type localhost and a new password as shown.
In mysql queries table names may contain alphanumeric characters, underscore and dollar sign. In order to be able to use other ANSI characters you must place names in single backquotes.
`table-db`
But in bash they have different meaning and used for command substitution. In bash there are also several types of strings -- in double quotes and in single quotes. The difference between them is that in double quotes variable expansion and command substitution are performed, while in single quotes they don't. So you can use backquotes with mysql semantics within single quotes as is
mysql -e 'CREATE DATABASE `table-db`;'
but must escape them when using within double quotes, so that they wouldn't be interpreted by bash as command sustitution.
mysql -e "CREATE DATABASE \`table-db\`;"
As you want to get the database name from variable you need to place it beyond single quote strings, like that:
mysql -e "CREATE DATABASE \`$dbname\`;"
or like that:
mysql -e 'CREATE DATABASE `'$dbname'`;'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With