mysql create db and user

I get asked this a lot. Here’s how to create a MySQL database and user from the command line.

Log in as the root user (mysql -u root -p) and then issue the following command:

mysql> create database owncloud;

In this example the name of my db is “owncloud”.

To create a user who “owns” the database, use this syntax:

mysql> grant all privleges on owncloud.*
to 'owncloud'@'localhost'
identified by 'mypassword';

Here we’re granting all rights over all tables in the owncloud database (owncloud.*) to a user called owncloud. Notice that the user and host names are enclosed in single quotes, as is the user’s password.

Whenever creating users or altering privileges on a database be sure follow up with a “flush” command:

mysql> flush privileges;
This entry was posted in Database, System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).