Create A MySQL/MariaDB Database For Drupal

Log into MySQL as root (assumes password is stored on /root/.my.cnf, otherwise you will have to enter a password):

  sudo -H mysql -p

Create a new database for your site:

  CREATE DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Create the database user and grant privileges:

  GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON databasename.* TO 'username'@'localhost' IDENTIFIED BY 'password';

Be sure to use backticks ( ` ) around the database name if you used a MySQL or MariaDB escape character (_ or %) in your database name. Additionally, when you want to use a _ character as part of a database name, you should also specify it as \_ in the GRANT statement. For example, because the underscore character is a wildcard, drupal_test_account.* should be `drupal\_test\_account`.* for security. Otherwise the underscores would match any character and could accidentally give access to other similarly named databases.

If successful, MySQL/MariaDB will reply with:

  Query OK, 0 rows affected

Flush the privileges to make sure the user has active privileges:

  FLUSH PRIVILEGES;