Community Documentation

Step 2: Create the database

Last updated January 28, 2013. Created by sepeck on April 25, 2008.
Edited by manish_mics, amontero, bsporer, authentictech. Log in to edit this page.

Note: Since 8.x, Drupal can create the database itself if its database user has enough privileges. See the relevant change notice.

Before running the installation script, you must create an empty database and database user (a user name assigned the rights to use the Drupal database).

This page offers guidance for creating your Drupal database using a web browser-based control panel (such as "CPanel" or "Plesk"), or by using phpMyAdmin (another browser-based database utility), or by creating the database directly from the MySQL or PostgreSQL command prompt (for more advanced users).

Create a database and user via a browser-based control panel

Most web hosting accounts provide a Web-based control panel to help you administer your site. These tools include easy-to-use features for creating a new database, and for creating a "user" with rights to the database. To create a database using a browser-based control panel consult the documentation or ask your web host service provider.

When you create the user for your database, you may see a page where you can specify the privileges that user will have for various operations on the database. In most web control panels' "database wizard", if you simply check "All" privileges for the user you create (and then uncheck "Grant" if it is listed as a privilege) your user will be set up correctly.

Take note of the username, password, database name and hostname (eg. are you installing in http://example.com, or in http://drupal.example.com, or http://example.com/blog etc.) as you create the database. You will enter these items into fields in your browser when running the install script (see next page).

Note that in many cases when creating databases and users via a web-based interface, the username you use to log into your control panel is added as a prefix to the database name and possibly to the database username as well. For example, if you log into your site's control panel as "webadmin" and create a database named "drupal7db" and a user for that database named "d7user", when running the Install script (see next page) the database and user may need to be typed in as "webadmin_drupal7db" and "webadmin_d7user". (This is because many hosting accounts are on shared servers, and on one server each database and user name must be unique across all accounts on the server.)

If you have created your database and user via a web-based interface, you can skip the remainder of this page and continue with the install instructions on the next page.

Create a database and user using phpMyAdmin

This presumes you have root access to phpMyAdmin

  1. Log in to phpMyAdmin as the root user.
  2. Click Privileges and Add a new User OR you can use root user credential as well..
  3. In the User name field, enter the username you wish to use.
  4. In the Host field, select Local which is more secure, unless you will be accessing the database with this user from another server.
  5. Enter or generate a password for the user.
  6. In the Database for User list, select Create database with same name and grant all privileges and click Go.

You have now created a user that has all privileges only on the database with the same name. This is more secure than using a general username and password for all your sites on the same server, as it limits access to your databases if someone gets hold of your database logins.

If you want to have a different name for database and user, just select the created database, then click the operations tab. You will find an option Rename database to. If you need more details about using PHPMyAdmin, check out the official wiki.

Take note of the username, password, database name and hostname (eg. are you installing in http://example.com, or in http://drupal.example.com, or http://example.com/blog etc.) as you create the database. You will enter these items into fields in your browser when running the install script.

Note that in many cases when creating databases and users using a web interface, the username you use to log in to your control panel is added as a prefix to the database name and possibly to the database username as well. For example, if you log into your site's control panel as "webadmin" and create a database named "drupal7db" and a user for that database named "d7user", when running the Install script (see next page) the database and user may need to be typed in as "webadmin_drupal7db" and "webadmin_d7user". (This is because many hosting accounts are on shared servers, and on one server each database and username must be unique across all accounts on the server.)

If you have created your database and user via phpMyAdmin, you can skip the remainder of this page and continue with the install instructions on the next page.

Create a database from the command line

If you do not use a Web control panel or are experienced with and prefer to use MySQL or PostgreSQL commands, you can follow the information below.

Additional information about privileges, and instructions to create a database using the command line are available in INSTALL.mysql.txt (for MySQL) or INSTALL.pgsql.txt (for PostgreSQL).

Create a database using MySQL commands

The database should be created with UTF-8 (Unicode) encoding, for example utf8_general_ci.

For information on installing and configuring MySQL see http://dev.mysql.com/tech-resources/articles/mysql_intro.html

In the following examples, 'username' is an example MySQL user who will have the CREATE and GRANT privileges and 'databasename' is the name of the new database Use the appropriate names for your system.

  1. Create a new database for your site.

    mysqladmin -u username -p create databasename

    MySQL prompts for the 'username' database password, and creates the initial database files.

  2. Log in and set the access database rights:

    mysql -u username -p

    MySQL prompts for the 'username' database password.

  3. At the MySQL prompt, set the permissions using the following command:

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

    In this case:

    • 'databasename' is the name of your database
    • 'username@localhost' is the username of your MySQL account
    • 'password' is the password required for that username

    You will need the ` around the database name if you have used a MySQL escape character in your schema name.

    Eg: drupal_test_account.* should be drupal\_test\_account.* for security (underscore is a wildcard). This requires the ` wrapper. `drupal\_test\_account`.*

    Note: unless your database user has all of the privileges listed above, you will not be able to run Drupal.

  4. If successful, MySQL will reply with:

    Query OK, 0 rows affected

  5. To activate the new permissions, enter the following command:

    FLUSH PRIVILEGES;

  6. Now exit the MYSQL prompt by typing:
    exit
    The server will answer by saying
    Bye

Create a database using PostgreSQL

The database must be created with UTF-8 (Unicode) encoding.

  1. Create a database user
    This step is only necessary if you don't already have a user setup (e.g. by your host) or you want to create new user for use with Drupal only. The following command creates a new user named 'username' (you should substitute this with the desired username), and prompts for a password for that user:

    createuser --pwprompt --encrypted --no-adduser
    --no-createdb username

    If everything works correctly, you'll see a CREATE USER notice.

  2. Create the database
    This step is only necessary if you don't already have a database setup (e.g. by your host) or you want to create new database for use with Drupal only. The following command creates a new database named "databasename" (you should substitute this with the desired database name), which is owned by previously created "username":

    createdb --encoding=UNICODE --owner=username databasename

    If everything works correctly, you'll see a CREATE DATABASE notice.

Comments

Flushing privileges unnecessary for MySQL

For MySQL, you do not have to do the FLUSH PRIVILEGES when you use the GRANT command. The statement "To activate the new permissions" is false since they were already activated.

Cheers,
Geert

PostgreSQL 9 and bytea

I'm using drupal 6 with a PostgreSQL database.

I just installed postgres 9 on my MacBook Pro and my drupal site began giving me all sorts of these messages...

# warning: array_keys() [function.array-keys]: The first argument should be an array in /Users/ian/GoMOOS/XAMPP/odpdx.gmri.org/htdocs/includes/common.inc on line 3416.
# warning: Invalid argument supplied for foreach() in /Users/ian/GoMOOS/XAMPP/odpdx.gmri.org/htdocs/includes/common.inc on line 3419.

I fixed this by adding "set bytea_output = escape; " to includes/database.pgsql.inc. The code is below.

/**
* Helper function for db_query().
*/
function _db_query($query, $debug = 0) {
global $active_db, $last_result, $queries;

if (variable_get('dev_query', 0)) {
list($usec, $sec) = explode(' ', microtime());
$timer = (float)$usec + (float)$sec;
}
// bytea fix, preface query with set....
$query = "set bytea_output = escape; " . $query ;
$last_result = pg_query($active_db, $query);

Connection to Oracle

Could you provide some info with installation of Drupal 7 on Oracle.
Thank you,
DE

_

These links can help you more about Drupal and Oracle. I hope you can use them for installing Drupal on Oracle.
http://groups.drupal.org/node/24398
http://inode.me/tutorials/how-to-drupal-7-oracle-xe-install

Doubt is the father of invention..... Hubmesh

No can do

I followed your instructions to the T using phpMyAdmin and still can't get pass this step. I keep getting this error:

SQLSTATE[42000]: Syntax error or access violation: 1286 Unknown storage engine 'InnoDB'

I have MySQL 5.5.9-community installed. I've installed Drupal 6.20 before with no issues. Please advise.

Collation

You might want to mention something about choosing collation if you're building a localized site. Some languages have characters that migth turn out in the wrong alphabetical order in sorted queries if you go by the general collation, for instance scandinavian languages (åäöÅÄÖ and similar should be in the end of listings but are shown in proximitiy to aAoO).

Instructions for Installing on godaddy.com

If you are installing drupal on Godaddy.com, then be sure to change the "Host Name" under "Advanced Options" to the complete host name given in the Godaddy hosting center account under databases for your database.

Hostname will look something link: nameofthedatabase.db.7235321.hostedresource.com

Neil

Installing on another mysql server

i would like to install the drupal 6 in my on desktop pc and database on the other mysql database contating server

in one pc all is worked well,

but when installing on the another server having ip 192.168.200.70 with ubuntu as OS

and apache/XAMPP in windows to upload files on webserver having ip 192.168.200.60

I got the error like,

Failed to select your database on your MySQL database server, which means the connection username and password are valid, but there is a problem accessing your data. MySQL reports the following message: Host '192.168.200.70' is not allowed to connect to this MySQL server.

* Are you sure you have the correct database name?
* Are you sure the database exists?
* Are you sure the username has permission to access the database?

Please help me to solve it

You may need to explicitly

You may need to explicitly allow connection from your PC's IP address to your MySQL server.

Installing Drupal on OS X Lion

For those who are struggling with postgres:
https://discussions.apple.com/thread/3199015?start=15&tstart=0

Creating database is not sufficient, it is also necessary to enable TCP connections. Link above gives details.

For C-Panel Users

I found this to be pretty straight forward and easy. In the Databases section of c-panel use the "MySQL Databases" or you can use "MySQL Database Wizard", which walks you through the whole process step by step.

If you use "MySQL Databases" create a database, then a user. Make sure you link the two in the "add user to database" section.

If you use shared hosting the name of the database and user are "youradminusername"_"nameyouspecified", which is displayed easily for you to see.

Zach

Command line instructions for postgres incorrect.

This is likely going to be like nailing jello to the wall. Many OS's will have postgresql or mysql as packages, but there is some variation in where stuff is put, and what the unprivileged user is called. So for example, this is what I had to do on FreeBSD 8.

1. The default database is in /usr/local/postgresql, not /var. I don't like data to reside in /usr. The unprivileged user is pgsql.

mkdir /opt
mkdir /opt/postgres
chown pgsql /opt/postgres

This gave me a place to put the database

2. On freebsd the commands to initialize and create must be run as the owner of the database system -- pgsql.

su pgsql -c "initdb -D /opt/postgres"

3. The database engine has to be started before you can create a databse

su pgsql -c "pg_ctl -D /opt/postgres -l /var/log/pg.log start"

4. NOW you can create the admin user and the database, but to create with unicode you have to use Template0

su pgsql -c "create user --pwprompt --encrypted --no-adduser --no-createdb drupal_admin"
su pgsql -c "createdb --encoding=UNICODE -T template0 --owner drupal_admin DrubleBase"

This is going to vary with each OS.

What about SQL lite.?

What about SQL lite.?

Create MySQL Database with UTF-8 encoding

The documentation says that the "The database should be created with UTF-8 (Unicode) encoding, for example utf8_general_ci." but doesn't give details.

To achieve this by the mysql command line interface use the following commands:
mysql -u root -p # Login
CREATE DATABASE databasename CHARACTER SET utf8; # Create with utf-8

When using mysqldump/mysql for backup/restore also force both server and client to utf8 by
inserting into "/etc/mysql/my.cnf"
default-character-set = utf8 # Server
skip-character-set-client-handshake # Force client

Otherwise you could experience charset trouble when you once migrate the data to a different location.
(Make sure not to break other databases on your system in case they rely on anothe charset for mysql)

Check: Login to your database and isse following commands, you should see everywhere utf8:
SHOW VARIABLES LIKE 'char%';
SHOW VARIABLES LIKE 'collation%';

Most of the information taken from the following blog post - Thanks to them!
http://www.bluebox.net/about/blog/2009/07/mysql_encoding/

Different privileges to INSTALL.mysql.txt

In drupal 7 in INSTALL.mysql.txt it only says:

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

Which is different to what is mentioned on this page.

Extra ones mentioned on this page are:

LOCK TABLES, CREATE TEMPORARY TABLES

What's the deal? The doco should be the same in both places.

This was added in revision 976154

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Level
Beginner
Audience
Programmers, Site administrators
Drupal’s online documentation is © 2000-2013 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. Comments on documentation pages are used to improve content and then deleted.