Anurag Kumar
Anurag Kumar

Reputation: 59

drop database having exclamation and backtick

I am trying to drop a database having special characters (!`) in it.

MySQL [test]> show databases;
+-------------------------+
| Database                |
+-------------------------+
| d1                      |
| d2                      |
| db1`; select 'oops!'    |
MySQL [test]> drop database `db1\`\; select \'oops!\'`;
ERROR: Unknown command '\;'.
ERROR: Unknown command '\''.
ERROR: Unknown command '\''.
    `> Ctrl-C -- exit!
Aborted
MySQL [test]> drop database "db1`; select 'oops!'";
ERROR 1064 (HY000): [33792] syntax error: syntax error near ""db1`; select 'oops!'""
LINE: drop database "db1`; select 'oops!'"
                    ^

I tried escaping these characters but it is not deleting for me. Including double quotes throws syntax error. I tried MySQL 5.6/5.7.

Upvotes: 2

Views: 206

Answers (2)

Nick
Nick

Reputation: 147146

To escape a backtick, you need to double it (see the manual). The other characters shouldn't need escaping:

DROP DATABASE `db1``; select 'oops!'`

If you can control SQL_MODE, you can set ANSI_QUOTES and surround the string in double quotes:

SET SQL_MODE = 'ANSI_QUOTES';
DROP DATABASE "db1`; select 'oops!'"

Upvotes: 3

KAUSHAL MAURYA
KAUSHAL MAURYA

Reputation: 17

try:

drop database Database_name;

Upvotes: -1

Related Questions