How to See Which MySQL Database Is Currently Selected?

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    |
+------------+

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.