How to DROP a database in MySQL with character '?' in its name?

MySQLMySQLi Database

To drop a database with the character ‘?’ in its name, you need to use backtick symbol around the database name. The syntax is as follows −

DROP DATABASE `yourDatabaseName`;

To understand the above syntax, let us create a database. The query to create a database is as follows −

mysql> create database `test?data`;
Query OK, 1 row affected (0.14 sec)

So, I have a database with? character. The query to show all databases is as follows −

mysql> show databases;

The following is the output −

+-----------------------+
| Database              |
+-----------------------+
| business              |
| commandline           |
| database1             |
| databasesample        |
| education             |
| hb_student_tracker    |
| hello                 |
| information_schema    |
| javadatabase2         |
| javasampledatabase    |
| mybusiness            |
| mydatabase            |
| mysql                 |
| onetomanyrelationship |
| performance_schema    |
| rdb                   |
| sample                |
| sampledatabase        |
| schemasample          |
| sys                   |
| test                  |
| test3                 |
| test?data             |
| universitydatabase    |
| web                   |
| webtracker            |
+-----------------------+
26 rows in set (0.09 sec)

To drop a database with? character, you need to use backtick symbol around the database name. The query is as follows −

mysql> drop database `test?data`;
Query OK, 0 rows affected (0.32 sec)

Now you can check there is no database with test?data. The query is as follows −

mysql> show databases;

The following is the output −

+-----------------------+
| Database              |
+-----------------------+
| business              |
| commandline           |
| database1             |
| databasesample        |
| education             |
| hb_student_tracker    |
| hello                 |
| information_schema    |
| javadatabase2         |
| javasampledatabase    |
| mybusiness            |
| mydatabase            |
| mysql                 |
| onetomanyrelationship |
| performance_schema    |
| rdb                   |
| sample                |
| sampledatabase        |
| schemasample          |
| sys                   |
| test                  |
| test3                 |
| universitydatabase    |
| web                   |
| webtracker            |
+-----------------------+
25 rows in set (0.00 sec)

Look at the above output, there is no database with name test?data;

raja
Published on 26-Feb-2019 16:44:16
Advertisements