Create a new database and user, and set privileges to the user | Using MySQL console-terminal

Written by
Date: 2012-06-24 07:58:43 00:00

Every time working on a new installation of Wordpress, Drupal or Joomla (not too often I must say), I have to look for the way to create de Database and the new user.

There is a simple way to create the MySQL database and the user and grant privileges to that user over the newly created Database. All at the same time, with the same terminal line.

Here is how.

First enter the MySQL prompt from the terminal

mysql -u root -p

Create the database.

CREATE DATABASE database-name;

Create the user and grant privileges over the database he will have to work on.

GRANT ALL PRIVILEGES ON database-name.* TO "user"@"hostname" IDENTIFIED BY "password";

Finish with flush privileges


That is it, now I will have a page to come and look for this when I need it. Hope it helps someone else too.