Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to drop database due to illegal character

Tags:

mysql

sql-drop

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>
like image 880
Oh Chin Boon Avatar asked Oct 01 '11 06:10

Oh Chin Boon


People also ask

How do I force drop a database in MySQL?

First, launch the MySQL workbench and log in to the MySQL Server. Second, right-click the database that you want to remove, for example, testdb2 and choose the Drop Schema... option. Third, MySQL Workbench displays a dialog to confirm the deletion.

What does dropping the database mean?

Dropping a database deletes the database from an instance of SQL Server and deletes the physical disk files used by the database. If the database or any one of its files is offline when it is dropped, the disk files are not deleted. These files can be deleted manually by using Windows Explorer.

Why drop database if exists?

IF EXISTS is used to prevent an error from occurring if the database does not exist. If the default database is dropped, the default database is unset (the DATABASE() function returns NULL ). If you use DROP DATABASE on a symbolically linked database, both the link and the original database are deleted.


1 Answers

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

like image 174
Mark Byers Avatar answered Oct 08 '22 03:10

Mark Byers