How to Create MySQL database and user

By | 2013/01/21

Here is quick way to create a MySQL database and user. This is useful for WordPress, Drupal, or other LAMP apps.

Login to MySQL with the MySQL root password:

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Create the database named as desired:

mysql> create database mydatabase;
Query OK, 1 row affected (0.00 sec)

Create a username and password and setup full access for that user to your database:

mysql> grant all on mydatabase.* to 'username'@'localhost' identified by 'thepassword';
Query OK, 0 rows affected (0.00 sec)

Some cleanup:

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit