1. Launch MySQL in the terminal session with the following command:
mysql -u root -p
You will be prompted for the database administrator (root) password. Once logged in you will see a new MySQL prompt.
user@getondrupal.com:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 141 Server version: 5.0.75-0ubuntu10.2 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
At the MySQL prompt the following command will show you a listing of existing databases on the server. Note: All commands in MySQL end with a semicolon(;).
SHOW DATABASES;
The output should appear like this:
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+ 2 rows in set (0.00 sec) mysql>
2. After verifying that you haven't already created the database you'd like to use, we'll go ahead and create a new Drupal database. At the MySQL prompt issue the 'CREATE DATABASE' command followed by the name of the Drupal database you would like to create.
CREATE DATABASE drupal_db;
The output should appear as:
mysql> CREATE DATABASE drupal_db; Query OK, 1 row affected (0.00 sec) mysql>
We can verify the creation of the new database with the 'SHOW DATABASES' command we used previously. The output look like:
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | drupal_db | | mysql | +--------------------+ 3 rows in set (0.00 sec) mysql>
3. Next, we'll need to create an user account with the 'GRANT' command that can use the database we created. Note: on very long commands you can press enter and the command will continue in the new line with the '-> ' prompt.
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON drupal_db.*
->TO 'drupal_dbuser'@'localhost' IDENTIFIED BY 'password';
Be sure to replace the following variables from above with your own:
drupal_db.*
-> your database name
'drupal_dbuser'
- > your database user name
'localhost'
- > the hostname of your database server (especially if hosted on a different host than your webserver)
'password'
- > the password you plan to log the database user with
4. Any time we create a new MySQL user or alter the permissions we want to propagate the changes. We achieve this with the FLUSH PRIVILEGES command.
mysql> FLUSH PRIVILEGES;
5. Your Drupal database is now set and we can exit the MySQL prompt with the 'QUIT" command. This should take you back to the terminal session.
mysql> QUIT; Bye user@getondrupal.com:~$