You can find out which MySQL database is currently selected by using the DATABASE() function, for example, like so:
SELECT DATABASE();
If no database is selected, it will return NULL, otherwise it will produce an output like the following:
+------------+
| DATABASE() |
+------------+
| db_name |
+------------+