Step-by-Step Guide to Select and Open Databases in MySQL

View All Databases

To see all available databases in your MySQL server, log in to the MySQL command-line interface and run:

SHOW DATABASES;

Example Output:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| my_database        |
| test               |
+--------------------+

Open a Specific Database (Command Line)

To start working with a specific database, use the USE command followed by the database name:

USE database_name;

Example:.

USE my_database;

Output:

Database changed

Once the database is selected, all subsequent SQL commands will target this database.

Verify the Selected Database

You can confirm the currently active database by running:

SELECT DATABASE();

Example Output:

+----------------+
| DATABASE()     |
+----------------+
| my_database    |
+----------------+

Open a Database Using MySQL Workbench

  • Launch MySQL Workbench
    Open MySQL Workbench and connect to your MySQL server.

  • List All Databases

    • In the Navigator pane (left side), you will see a list of available databases under the “Schemas” section.
    • If you don’t see it, click the Refresh button.
  • Open a Database

    • Double-click on the database name in the Navigator pane.
    • The selected database becomes active, and its tables and objects are visible in the Navigator.
  • Verify Active Database
    Run this query in the SQL Editor to confirm the active database:

SELECT DATABASE();

Best Practices

Use Descriptive Names

Use Descriptive Names
Organize databases with clear, descriptive names for easier identification.

Avoid Using Root
Always use a MySQL user with specific permissions for database operations.

Secure Your Data
Regularly back up your databases and restrict access to sensitive dat

Minimize Permissions
Only the necessary privileges for security are granted to users.

Select and Open Databases

Quiz: Test Your Knowledge