Advertisement

Google Ad Slot: content-top

MySQL USE DB


MySQL USE Database Statement


The USE statement in MySQL is used to select and switch to a specific database, making it the active database for subsequent queries.


Syntax:


USE database_name;


  • database_name is the name of the database you want to use.

Example: Switching to a Database


Switch to the school_db database


USE school_db;


After executing this command, all queries will run within school_db unless another database is selected.


Checking the Selected Database


To verify the active database:


SELECT DATABASE();



Listing Available Databases


To see all databases in MySQL:


SHOW DATABASES;






All Database statements:


✔ The USE statement sets the active database.

✔ All queries after USE database_name; apply to the selected database.

✔ Use SHOW DATABASES; to list available databases.

✔ Use SELECT DATABASE(); to check the current database.