Search code examples
mysqlsql-drop

Unable to drop database due to illegal character


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>

Solution

  • 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 ("`"):