MariaDB / How to Use Hyphens and Dots in Database Names

In MariaDB, to create a database with a name containing a hyphen (-) or a dot (.), wrap the entire name in backticks (`). For example, write it like CREATE DATABASE `test-test`; and CREATE DATABASE `test.test`;.

Why are backticks necessary?

A database name is an identifier used by MariaDB to distinguish objects. Without backticks, MariaDB does not interpret the hyphen in test-test as part of the name, and the dot in test.test may be interpreted as a separator between identifiers. Therefore, neither of the following statements is valid syntax for creating the intended database.

CREATE DATABASE test-test;
CREATE DATABASE test.test;

Executing each sentence results in a syntax error. The specifics of the error message may vary depending on the server version and client. Backticks are different from single quotes (') used to represent strings. The rules for identifiers in MariaDB can be found in MariaDB Identifier Names Document.

Creating and Checking a Database

The following example is executed on an SQL client connected to a MariaDB server. You need permission to create a new database, and if a database with the same name already exists, check its usage before creating it. Practice should be done in a separate test environment without existing data.

CREATE DATABASE `test-test`;
CREATE DATABASE `test.test`;
SHOW DATABASES;

If creation is successful, you can see the names in the list. Creation may fail if the name already exists or if there is insufficient permission. If you can make the name simple with English letters, numbers, and underscores, you can establish it like test_test to reduce confusion with quoting and tool compatibility.

Using Names with Dots

When selecting a database, enclose the entire name, including the dot, in backticks. Running the following statements displays the current database name as test.test.

USE `test.test`;
SELECT DATABASE();

When specifying both a database and a table together, enclose each separately and place a separating dot between them. In the example below, the first dot is part of the database name, and the dot outside the backticks separates the database and the table.

CREATE TABLE `test.test`.`example` (id INT);
INSERT INTO `test.test`.`example` VALUES (1);
SELECT id FROM `test.test`.`example`;

If executed in a separate empty practice database, the final query returns 1. Table creation and data insertion privileges are also required. In contrast, if you enclose everything as a single pair like `test.test.example`, it represents a single identifier containing a dot, rather than two different identifiers.

Points to check during operation

Just because it can be enclosed in backticks doesn’t mean all tools handle names with special characters in the same way. Test separately whether application connection settings, backup and restore tools, management tools, and server versions support those names. For example, MariaDB's catalog functionality has restrictions on database names containing dots depending on the client used to connect. For detailed conditions, refer to the MariaDB catalog documentation .

Case sensitivity of database names is affected by the operating system file system and lower_case_table_names settings. Do not assume existing names use different cases; check the actual names. Since this setting relates to server initialization, do not arbitrarily change it on an existing production server for troubleshooting purposes.

After finishing the practice, check the name and contents first before deleting the database. DROP DATABASE deletes the tables and data inside it, so do not execute the example delete commands on actual service databases. Use the following commands only in an empty environment that you created for testing purposes.

DROP DATABASE `test-test`;
DROP DATABASE `test.test`;

The examples were confirmed in an isolated MariaDB 12.3.3 on Windows for creation with or without backticks, database selection, and table queries. In other versions or management tools, check the behavior and permissions of that environment.