Requirement
Knowing the current selected database becomes very important when there are more than one databases created and you want to know on which database your queries were executed or will be executed in future.
MySQL provides a command using which you can use to know the current selected database.
MySQL command to view the current selected database is
SELECT DATABASE();
This command can be executed both from MySQL workbench or MySQL command line.
From Workbench
Open MySQL workbench and execute the above command. It will show the current selected database as shown below.
As can be seen from above image, the selected database is returned. Note that selected database is also displayed in bold at left side.
Open MySQL terminal, login using your username and password and execute the above command. It will display the selected database as shown below.
If no database is selected, such as when you login to the terminal for the first time, this command will return
null
.