How to Check the Currently Selected MySQL Database via Command Line and MySQL Workbench

  • To check which MySQL database is selected, you can use different methods in both the command line and MySQL Workbench.
Command Line:
  • Open a terminal or command prompt.
  • Connect to the MySQL server using the following command:


    mysql -u your_username -p

  • Replace `your_username` with your actual MySQL username. You will be prompted to enter your password.
  • Once connected, you can check the currently selected database using the following command:


    SELECT DATABASE();

  • This query will return the name of the currently selected database.
MySQL Workbench:
  • Open MySQL Workbench and establish a connection to your MySQL server.
  • In the SQL Editor window, type the following query:


    SELECT DATABASE();

  • Click on the "Execute" button (or press `Ctrl+Enter` or `Cmd+Enter` on macOS) to run the query.
  • The result will be displayed in the result panel below the query editor, showing the name of the currently selected database.
  • It's important to note that if no database is selected explicitly, the default database will be used for queries and operations. In MySQL, the default database is often set to "mysql," which is the system database containing user and privilege information.

No comments:

Post a Comment