How to create and delete a MySQL database


MySQL organizes information into databases; each table holds specific data. Below we will explain how to list, create and delete databases in MySQL. To do this you will need access to run mysql queries either via SSH, or through phpMyAdmin.

You can easily view available databases by typing the command:

 SHOW DATABASES;

 When running the command make sure you remember to put the ; (semicolon) character at the end of it. When running the command it should like the following:

 mysql> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| test |

+--------------------+

4 rows in set (0.01 sec)

 

Creating a database:

 CREATE DATABASE databasename;

 For the sake of this guide, the data based will be called "testone". 

 mysql> CREATE DATABASE testone;

 mysql> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| information_schema |

| testone |

| mysql |

| performance_schema |

| test |

+--------------------+

5 rows in set (0.00 sec)

 

You would delete a MySQL database with this command:

Be very careful when you DROP A DATABASE IT IS GONE FOR GOOD! The best route would be to backup the database first using mysqldump command explained here and then use the DROP command below. This way you have a backup to restore should you need it.

 DROP DATABASE databasename;

 

 

Posted in
Last update:
2016-06-10 15:25
Average rating:0 (0 Votes)