Unable to drop database due to illegal character

Oh Chin Boon picture Oh Chin Boon · Oct 1, 2011 · Viewed 10k times · Source

How can i drop a database containing the "-" symbol?

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| vms01              |
| vms-0.1.0          |
+--------------------+
4 rows in set (0.00 sec)

mysql> drop database vms-0.1.0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use n
    ear '-0.1.0' at line 1
    mysql>

Answer

Mark Byers picture Mark Byers · Oct 1, 2011

You can quote identifiers (for example table and column names) with backticks:

drop database `vms-0.1.0`

See the documentation for more details: Schema Object Names.

The identifier quote character is the backtick ("`"):