Switch Databases With the USE Command

Technology illustration

Endai Huedl/Getty Images

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> ​

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

mysql> ​​

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. "Switch Databases With the USE Command." ThoughtCo, Aug. 28, 2020, thoughtco.com/use-sql-command-2693990. Bradley, Angela. (2020, August 28). Switch Databases With the USE Command. Retrieved from https://www.thoughtco.com/use-sql-command-2693990 Bradley, Angela. "Switch Databases With the USE Command." ThoughtCo. https://www.thoughtco.com/use-sql-command-2693990 (accessed June 6, 2023).