MySQL – Select DATABASE
MySQL Server can contain multiple databases and can serve multiple clients simultaneously. So, when a client connects to or opens a mysql command prompt, a database (from existing multiple databases) should be selected to run the SQL queries or operations. In this tutorial, we shall learn to select a database in MySQL, from multiple databases.
Syntax – Select Database in MySQL
Following is the syntax of SQL query to select a database in MySQL in mysql command prompt.
database_name : Name of the database to use and run the queries upon.
Now we shall see list of existing databases in MySQL Server and select one of them to use with SQL queries or operations.
USE db2; selects database db2 for any subsequent queries on a database.
Change or switch DATABASE in MySQL
To change or switch DATABASE, run the same USE database_name query with the new database name that you wish to work on. In the example shown above, USE db3; changes the database, from db2 to db3, on which your SQL queries effect on.