Step 3: Create a database
If you are installing Drupal on a test site, you can skip this step. When running the installer script (next step), it's enough to provide the database username and password with permission to create a new database.
If you are installing Drupal on a public web server, you should first create a database and grant access to a less privileged user. The database user you specify during installation will connect to the database every time a page is loaded.
This page provides instructions on how to create a Drupal database using one of the following methods:
- Web-based control panel (e.g., CPanel or Plesk)
- PhpMyAdmin
- Using SQL commands (via command line)
- Using MySQL / MariaDB commands
- Using PostgreSQL commands
Allowed Characters in MySQL / MariaDB Database Names
- If you use uppercase letters in the database name, they will be converted to lowercase.
- Allowed characters: a..z, 0..9, and “_” (underscore).
Create a Database and User via Browser-Based Control Panel
Most web hosting accounts provide a web control panel to help you administer your site. These tools include user-friendly features for creating a new database and a “user” with database privileges. To create a database using a browser-based control panel, refer to its documentation or contact your web hosting provider.
When creating a user for your database, you may see a page allowing you to assign privileges to the user. In most control panel “database wizards,” simply selecting “All” privileges (and then unchecking “GRANT” if it’s listed) will configure the user properly.
Record the username, password, database name, and host name (e.g., you’re installing on http://example.com, http://drupal.example.com, or http://example.com/blog, etc.). You'll enter this information in your browser during the installation script.
Note: In many cases, when creating databases and users via a web interface, the control panel login username is added as a prefix to both the database and database user names. For example, if you log into your site’s control panel as “webadmin” and create a database named “drupal8db” and a user “d8user,” you may need to enter "webadmin_drupal8db" and "webadmin_d8user" during the installation. This is because many hosting accounts are on shared servers, where each database and username must be unique across all accounts.
Create a Database and User Using phpMyAdmin
The most secure way to create a database using phpMyAdmin is to create a user who has all privileges to a new database but none to other databases. This is safer than using a shared username and password for all your sites on the same server.
Note: This procedure assumes you have root access to phpMyAdmin and are using phpMyAdmin 3.5.x.
- Log into phpMyAdmin as root user.
- Click “Users”, then click “Add user”. (Note: You can also use the root user credentials.)
- In the Username field, enter the desired username.
- In the “Host” field, select “Local” for better security, unless accessing from another server.
- Enter or generate a password for the user.
- In the Database for user section, select “Create database” with the same name and grant all privileges.
- Ensure COLLATION is set to utf8mb4_unicode_ci or utf8mb4_general_ci.
- Note: The difference between these collations is in character comparison and sorting. utf8mb4_general_ci is slightly faster, while utf8mb4_unicode_ci is more accurate. Use utf8mb4_unicode_ci if unsure.
- Note: If COLLATION can't be set during this process, you can change it later under “Operations” after selecting the database.
8. Click Go to create the user.
phpMyAdmin will create a new database with the same name as the user account. If you want a different database and user name:
- Click Databases, then click the database name you want to rename.
- Click “Operations”.
- In the “Rename database to” section, enter the new database name.
- Click Go.
For more phpMyAdmin help, see the official wiki.
Create a Database Using the Command Line
If you don’t use a web control panel or are experienced with MySQL, MariaDB, or PostgreSQL and prefer those, the next sections explain how.
More on privileges and database creation via command line is in INSTALL.mysql.txt (MySQL/MariaDB) and INSTALL.pgsql.txt (PostgreSQL).
Create a Database Using MySQL / MariaDB Commands
Note: The database must use UTF-8 (utf8mb4) encoding with collation utf8mb4_unicode_ci or utf8mb4_general_ci. The difference relates to character comparison and sorting. utf8mb4_general_ci is slightly faster; utf8mb4_unicode_ci is more accurate. Use utf8mb4_unicode_ci if unsure.
For installing and configuring MySQL, visit http://dev.mysql.com/doc/refman/5.7/en/index.html.
For MariaDB, visit https://mariadb.com/kb/en/.
In the examples below, 'username' is a MySQL/MariaDB user with CREATE and GRANT privileges, and 'databasename' is the new database name. Use the appropriate names for your setup.
- Create a new database:
mysql -u username -p -e "CREATE DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
- Log in and set access:
mysql -u username -p
- Create the user and assign privileges:
CREATE USER username@localhost IDENTIFIED BY 'password'; GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON databasename.* TO 'username'@'localhost' IDENTIFIED BY 'password';
Be sure to escape special characters. For example, use backticks around database names if they include underscores (_), which are wildcard characters. drupal_test_account.* should be `drupal\_test\_account`.*.
Note 1: The user/host combo for your Drupal installation must have all listed privileges (except maybe CREATE TEMPORARY TABLES).
Note 2: To restore a database dump created by Drush, add LOCK TABLES privilege.
More on GRANT: http://dev.mysql.com/doc/refman/5.0/en/grant.html.
- 'databasename' — your database name
- 'username' — your MySQL/MariaDB user
- 'localhost' — the Drupal host server
- 'password' — the user password
- Success response:
Query OK, 0 rows affected
- Flush privileges:
FLUSH PRIVILEGES;
- Exit MySQL/MariaDB:
exit
- Expected response:
Bye
Create a Database Using PostgreSQL
The database must use UTF-8 (Unicode) encoding.
1. Create a database user
This step is needed only if your host hasn’t already set one up or you want a dedicated Drupal user. This creates a new user “username” and prompts for a password:
createuser --pwprompt --encrypted --no-adduser --no-createdb username
If successful, you’ll see CREATE USER.
2. Create the database
This step is needed only if your host hasn’t already created one or you want a new one for Drupal:
createdb --encoding=UNICODE --owner=username databasename
If successful, you’ll see CREATE DATABASE.
Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.