Home  >  Article  >  Database  >  Can I Use Dots in MySQL Database Names?

Can I Use Dots in MySQL Database Names?

DDD
DDDOriginal
2024-10-31 00:40:03597browse

Can I Use Dots in MySQL Database Names?

Creating Databases with Dots in MySQL

Can MySQL databases contain dots in their names? This article addresses this question, particularly for MySQL version 5.1.22.

Answer:

The answer is no, MySQL does not allow creating databases with dots in their names. It is generally advisable to avoid using dots in any identifier, including database and field names. The preferred alternative is the underscore character, which serves the same purpose without causing confusion.

However, there may be instances where you have a compelling reason to use unusual characters in a table or field name. In such cases, you can escape the identifier using the backtick character:

CREATE DATABASE `my.database`;
CREATE TABLE `my_table` (`my.field` INT);

By escaping the identifier with backticks, you can include characters that are otherwise illegal in database and field names. It is also considered good practice to consistently escape all field names with backticks, regardless of necessity.

The above is the detailed content of Can I Use Dots in MySQL Database Names?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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