Home > Database > Mysql Tutorial > Detailed introduction to the MySQL code case for creating a database with special characters

Detailed introduction to the MySQL code case for creating a database with special characters

黄舟
Release: 2017-03-21 13:48:45
Original
1247 people have browsed it

This article mainly introduces you to MySQLHow to create a database name with special characters. The article gives detailed sample code. Friends in need can refer to the following. Let’s take a look together.

Preface

This article explains how to create a database name with special characters in MySQL. The special characters here include: !@# $%^

##The method is as follows

Use backticks` to include the database name, backticks`(the use of quotes is not allowed) means in English In the input method state, press the Esc key corresponding to the key below to come out. Of course, when the database name is not included in backticks`, if the database name contains special characters, an error will be reported.

For example, using the following creation command will report an error:

mysql> CREATE DATABASE www.mafutian.net DEFAULT CHARSET UTF8;
1064 - Erreur de syntaxe près de '.mafutian.net DEFAULT CHARSET UTF8' à la ligne 1
Copy after login

Correct creation method:

mysql> CREATE DATABASE `www.mafutian.net` DEFAULT CHARSET UTF8;
Query OK, 1 row affected
Copy after login

As shown below:

Another example:

mysql> CREATE DATABASE `!@#$%^&*()_+.` DEFAULT CHARSET UTF8;
Query OK, 1 row affected
mysql> USE !@#$%^&*()_+.
 -> ;
1064 - Erreur de syntaxe près de '!@#$%^&*()_+.' à la ligne 1
mysql> USE `!@#$%^&*()_+.`;
Database changed
mysql> SELECT database();
+---------------+
| database() |
+---------------+
| !@#$%^&*()_+. |
+---------------+
1 row in set
Copy after login

As can be seen from the above, when selecting a database, you also need to use backticks ` to enclose the database name. As shown below:

Similarly, when deleting a database, you also need to use backticks ` to enclose the database name:

mysql> DROP DATABASE `www.mafutian.net`;
Query OK, 0 rows affected
mysql> DROP DATABASE `!@#$%^&*()_+.`;
Query OK, 0 rows affected
Copy after login

Summary

The above is the detailed content of Detailed introduction to the MySQL code case for creating a database with special characters. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template