How to create and delete a database using MySQL

/ #Mysql

When setting up a dynamic website, you're going to need a database. MySQL is one of the most popular, and in this guide I'll show you how to create one using the command line.

Logging in

The first thing you need to do is to log in to your database. Normally you either have a local version of MySQL or you have to SSH into your web server.

When you're in the MySQL command line, you're ready to proceed to the next step.

Creating a database

Using commands to create a new database is actually very simple. Just write the following command and hit enter:

$ create database NAMEOFTHEDATABASE;

You can call it whatever you want. Let's just quickly check that the database was created.

$ show databases;

If you run the code above, you'll see a list of databases. Hopefully, the one you created should be in there somewhere.

Deleting a database

Sometimes you need to delete a database. Write the following command (be really sure that you know what you are doing):

$ drop database NAMEOFTHEDATABASE;

And that's it. The database is gone and there's no way of getting it back (as long as you don't have a backup).


No comments yet...

Add comment


Please log in to comment!


Subscribe to my weekly newsletter. One time per week I will send you a short summary of the tutorials I have posted in the past week.