Creating a Database for Drupal Installation

One of the fundamental components we need to prepare before starting a Drupal installation is the database. Content, users, configuration, and much of the information Drupal needs while running are all stored in this database.

Drupal supports different databases such as MySQL, MariaDB, PostgreSQL, and SQLite. The version we use needs to be compatible with the Drupal version. For example, Drupal 11 supports MySQL 8.0+, MariaDB 10.6+, PostgreSQL 16+, and SQLite 3.45+.

In this article, we'll proceed using MySQL/MariaDB as our example.

What Do We Need Before Creating a Database?

On the Drupal installation screen, we're basically asked for the following information:

  • Database name
  • Database username
  • Database password
  • Database server
  • Port information, if needed

For example, we can set up the following structure on the server:

text
Database: drupal_site
User: drupal_user
Host: localhost

It's good practice to create a separate database user specifically for Drupal here. Drupal doesn't need to work with a user like root that can access all databases.

Drupal's official documentation also recommends creating the database in advance on public servers and giving Drupal a separate user with more limited privileges.

Connecting to MySQL or MariaDB

If MySQL or MariaDB is installed on a server such as Ubuntu, we can first connect to the database console:

bash
sudo mysql

If a password is configured for the root user's connection:

bash
mysql -u root -p

we can use this instead.

In the second command, -u root specifies which user we'll connect to MySQL with, and -p indicates that we'll be asked for a password.

Once the connection succeeds, a console similar to the following will open:

text
mysql>

Now we can create the database and the user.

Creating the Database for Drupal

As an example, let's create a database named drupal_site:

sql
CREATE DATABASE drupal_site
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

Here we're not just creating the database — we're also specifying its character set.

utf8mb4 supports Unicode characters. It's the character set that should be used in Drupal databases to avoid problems with Turkish characters, different alphabets, and characters like emoji.

utf8mb4_unicode_ci is the collation value used for comparing and sorting characters. Drupal's official installation documentation recommends using utf8mb4_unicode_ci or utf8mb4_general_ci together with utf8mb4 on MySQL/MariaDB databases.

If we want to check that the database was created:

sql
SHOW DATABASES;

we can use this command.

If:

text
drupal_site

appears in the list, this step is complete.

Creating a Database User for Drupal

Now let's create a user that only this Drupal project will use:

sql
CREATE USER 'drupal_user'@'localhost'
IDENTIFIED BY 'GucluBirSifreBuraya';

Here:

text
drupal_user

is the username.

localhost specifies that this user can only connect from the same server. If Drupal and MySQL are on the same server, this is generally the structure we want.

In a real project, instead of a simple or reused password like the one in the example, a strong password unique to the project should be used.

Granting Database Privileges to the User

Creating the user doesn't yet mean it can access the drupal_site database. We also need to grant the necessary privileges:

sql
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES
ON `drupal_site`.*
TO 'drupal_user'@'localhost';

Although the command looks a bit long, what it does is simple: it allows the drupal_user user to perform only the operations it needs on the drupal_site database.

Since Drupal will create tables during installation, it needs CREATE, and since it will later read and modify content and configuration data, it also needs privileges like SELECT, INSERT, UPDATE, and DELETE. These permissions are also specified in Drupal's official installation documentation.

Particular attention should be paid here to:

sql
ON `drupal_site`.*

this part. This expression specifies that the user only has privileges on this database. This way, if there are other projects on the same MySQL server, the Drupal user cannot access their databases.

Let's Test the Connection

Before moving on to the Drupal installation, it's useful to check that the user we created can actually connect.

First, let's exit MySQL:

sql
exit;

Then let's connect with the new user:

bash
mysql -u drupal_user -p drupal_site

If the connection succeeds after entering the password, our basic preparation on the database side is complete.

For a simple check:

sql
SHOW TABLES;

we can run this.

Since we haven't installed Drupal yet, seeing:

text
Empty set

is normal. The necessary tables will be created automatically once the Drupal installation begins.

What Information Will We Enter on the Drupal Installation Screen?

When we reach the Set up database screen during Drupal installation, we can use the information we created.

For our example:

text
Database type: MySQL, MariaDB, Percona Server
Database name: drupal_site
Database username: drupal_user
Database password: ********
Host: localhost

If Drupal and the database run on the same server, the host is usually localhost.

In container-based setups like Docker, DDEV, or Docksal, the situation is different. Here, instead of localhost, the database container's service name can be used as the host.

For example, if the service is defined in Docker Compose as:

yaml
services:
  db:
    image: mariadb

then the database host will generally be:

text
db

This is because, from the Drupal container's perspective, localhost refers to its own container, not the database container.

Can We Create It From phpMyAdmin or a Hosting Panel?

If you don't have SSH access to the server, you don't have to create the database from the command line.

Through cPanel, Plesk, or phpMyAdmin, you can also create:

  1. a new database,
  2. a new user,
  3. database privileges for this user

The point to pay attention to here is the same as before: creating a separate user for Drupal and ensuring that user can only access the relevant database. Drupal's official installation documentation also lists creating a database via cPanel/Plesk and phpMyAdmin among the supported methods.

Some hosting panels automatically prepend the hosting account name to the database and username.

For example, while we might think we created:

text
drupal_site

the actual database name might be:

text
webuser_drupal_site

The actual database name shown in the panel needs to be entered on the Drupal installation screen.

If We're Using PostgreSQL

If PostgreSQL is preferred for the Drupal project, the process logic is the same: first the user is created, then the database belonging to that user.

For example:

bash
createuser --pwprompt --encrypted --no-adduser --no-createdb drupal_user

then:

bash
createdb --encoding=UNICODE --owner=drupal_user drupal_site

can be used.

The first command creates the drupal_user user, and the second creates the drupal_site database owned by this user.

In current Drupal versions, when using PostgreSQL, the pg_trgm extension also needs to be enabled on the relevant Drupal database.

For example:

sql
CREATE EXTENSION pg_trgm;

This command should be run while connected to the database Drupal will use, not another database.

Common Errors

If we get an error similar to:

text
Failed to connect to your database server

during Drupal installation, the first things to check are the database name, username, password, and host information.

For example, if MySQL is running inside a container but during Drupal installation we write:

text
Host: localhost

the connection may fail. In this case, we may need to use the Docker service name instead.

Another common problem is that the user can access the database but doesn't have permission to create tables. In this case, the connection succeeds, but the installation doesn't proceed because Drupal can't create tables during setup.

To check the user's privileges:

sql
SHOW GRANTS FOR 'drupal_user'@'localhost';

we can use this command. It's especially useful in cases where the connection works but the Drupal installation fails at the database step.

Conclusion

When preparing a database for Drupal, we're really performing three basic operations: creating a database belonging to Drupal, defining a separate user for that database, and granting the user the privileges it needs.

To summarize our full example:

sql
CREATE DATABASE drupal_site
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

CREATE USER 'drupal_user'@'localhost'
IDENTIFIED BY 'GucluBirSifreBuraya';

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES
ON `drupal_site`.*
TO 'drupal_user'@'localhost';

Once this information is ready, we can define the database connection on the Drupal installation screen and continue with the installation.

Especially in production environments, rather than giving Drupal the root database user, using a separate user that can only access the relevant project database provides a more correct structure both for management and for security.

Latest update: 18.09.2026 14:02