The Use Command

Choose the correct database each time you start a MySQL session with USE

Creating a database in MySQL doesn't select it for use. You have to indicate it with the USE command. The USE command is also used when you have more than one database on a MySQL server and need to switch between them.

You must choose the correct database each time you start a MySQL session. 

The USE Command in MySQL

The syntax for the USE command is:

mysql> ​USE [DatabaseName];

For example, this code switches to the database named "Dresses."

mysql> ​​USE Dresses;

After you select a database, it remains the default until you end the session or choose another database with the USE command.

Identifying the Current Database

If you are unsure which database is currently in use, use the following code:


This code returns the name of the database currently in use. If no database is currently in use, it returns NULL. 

To view a list of available databases, use:


About MySQL

MySQL is an open-source relational database management system that is most often associated with web-based applications. It is the database software of choice for many of the web's largest sites including Twitter, Facebook, and YouTube. It is also the most popular database management system for small- and medium-sized websites. Almost every commercial web host offers MySQL services. 

If you are just using MySQL on a website, you won't need to be involved with the coding—the web host will handle all that—but if you are a developer new to MySQL, you'll need to learn SQL to write programs that access MySQL.

mla apa chicago
Your Citation
Bradley, Angela. "The Use Command." ThoughtCo, Aug. 21, 2017, Bradley, Angela. (2017, August 21). The Use Command. Retrieved from Bradley, Angela. "The Use Command." ThoughtCo. (accessed March 24, 2018).