Creating a MySQL Database from the Command Line

A short one just to remind me, more than anything else.

Log into MySQL with the command

mysql -uroot -p

To see all existing databases, use

show databases;

To create a new database, where xxxx is the name of the database you want to create

create database xxxx;

To add a user, where yyyy is the username, and zzzz is the new user password

create user 'yyyy'@'localhost' identified by 'zzzz';

To assign the new user to the new database (xxxx is the database, yyyy is the username)

grant all on xxxx to yyyy;

About Peter Connolly

Pete Connolly is a lead developer at TechMediaNetwork, and also Technical Director at KP Direction LLC. An experienced IT Manager and PHP developer, Peter is currently leading a great team of developers managing http://space.com and http://livescience.com, developing on the Ruby on Rails platform. More..