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.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap