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 is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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