How to Create and Delete a MySQL Database

From Brian Nelson Ramblings
Revision as of 18:10, 12 March 2014 by Brian (Talk | contribs) (Alternative way to create and drop a database)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to create and delete a MySQL Database

Now that you have MySQL setup, I would assume that you will want to create a database.

Create a New MySQL Database

The first thing you will need to do is login into mysql

mysql -u <username> -p

Then you will want to create your database

create database <databasename>;

To verify that your database has been created run:

show databases;

Delete/Drop a MySQL Database

As before, the first thing you need to do is login to mysql

mysql -u <username> -p

Then drop the database

drop database <databasename>

To verify that it has been dropped

show databases;

Alternative way to create and drop a database

Alternatively this can also be done with -e flag with mysql

mysql -u <username> -p -e'create database <databasename>'

or

mysql -u <username> -p -e'drop database <databasename>'

Now just check and see if its there or been dropped

mysql -u <username> -p -e'show databases;'