MySQL: How to know which Database Schema you are on in Terminal

If you want to know which Database (Schema) you can currently log into you can run the below command in the mysql/MariaDB prompt.

select database();

+------------+
| database() |
+------------+
| mydb2      |
+------------+

1 row in set (0.000 sec)

As you can see I am currently in the mydb2 schema.

Note: If you are not logged into any database and you run the "select database();" query, you will get a NULL response.

select database();

+------------+
| database() |
+------------+
| NULL       |
+------------+

1 row in set (0.002 sec)
MySQL- How to know which Database Schema you are on in Terminal

td;lr


The SELECT DATABASE() is a useful way to check which database you are working with within the MySQL or MariaDB prompt, especially when dealing with multiple databases.

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!