I try to create a new Database via bash which has a dash in the name.
Thats what I tried:
echo "CREATE DATABASE IF NOT EXISTS db-name CHARACTER SET utf8 COLLATE utf8_general_ci" | mysql -uuser -ppw
That fails with the following error:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near
'-name CHARACTER SET utf8 COLLATE utf8_general_ci' at line 1
I added backticks then:
echo "CREATE DATABASE IF NOT EXISTS `db-name` CHARACTER SET utf8 COLLATE utf8_general_ci" | mysql -uuser -ppw
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near
'CHARACTER SET utf8 COLLATE utf8_general_ci' at line 1
I played around a bit and found out that mysql doesnt like backticks even without a dash in the name:
echo "CREATE DATABASE IF NOT EXISTS `dbname` CHARACTER SET utf8 COLLATE utf8_general_ci" | mysql -uuser -ppw
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near
'CHARACTER SET utf8 COLLATE utf8_general_ci' at line 1
I am kinda confused. Whats wrong here?
PS: In phpmyadmin it works as expected when adding backticks