7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial
FREELessons: 16Length: 1.5 hours

Next lesson playing in 5 seconds

  • Overview
  • Transcript

2.1 Creating and Deleting Databases

Before you can really do anything with MySQL, you need to have a database to work with. In this lesson, you will learn how to create a database to get started.

Related Links

2.1 Creating and Deleting Databases

One of the first things that you're gonna need to know how to do when working with MySQL is how to create a database and possibly also delete it as well. But let's go ahead and start with create first. So here I am at the MySQL prompt, and I wanna create a new database. So let's create a sample database. So the way that we're gonna do that, is we're going to use the create command. Then what do we wanna create? We want to create a database, and then we wanna give it a name. In this case, I'm simply gonna call it sample, and then make sure you end with a semicolon. Then we'll go ahead and hit Enter, and you'll see Query OK, 1 row affected. So now if we were to use the show databases command, you'll now see that we have a sample database in here. And you can do all the other things that we were doing before. You could look at the tables, although there's nothing in there yet, and ultimately start to work with this database. But let's say we've made a mistake and we don't really want the database sample or we mess it up and we wanna start from scratch, then we're gonna need to know how to delete databases. And you might initially think that you're gonna want to use the delete keyword. But in actuality when it comes to not only MySQL but many other databases out there, you're not gonna use the delete command. You're actually gonna use the drop command. And you're gonna see this quite often as we get into doing other things with tables as well, that instead of delete you're typically using drop. So what we wanna do, we wanna drop a database, and what database do we wanna drop? We wanna drop sample, and then end with a semicolon. And you can see here, Query OK. So let's go ahead and do show databases again, and now you'll see that we have no sample database anymore. Okay, so that's pretty nice, but in order for us to kinda keep building on this course as we go along, let's go ahead and create a new database that we can ultimately use for the rest of this course. So let's go ahead and say we want to create a database, and in this case we'll simply call it test and hit Enter. We'll do our show databases command, and we can see that we have our test database. And so that's gonna be the database that we're gonna use for the remainder of the course.

Back to the top