Wednesday 1 August 2012

How to create a MySQL Database from the Command Line

If you ever need to create a database from the command line.. here is how to do it:

(as an aside, a nice quick list of commands is available here)

http://www.bios.niu.edu/johns/bioinform/mysql_commands.htm

First login to mysql as root:

mysql -u root -p

MySql will promt you for a password.. Enter it now.

Now simply type:

CREATE DATABASE databasename;

Now create a user for this newly created database:

GRANT ALL ON databasename.* TO 'username'@'localhost';

set the password for this user

UPDATE mysql.user SET password=PASSWORD('password') WHERE user='username';

now to activate the permissions..

FLUSH PRIVILEGES;

all done..