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;