How to get database name of a site

Hi all,

How can I use these command frappe.conf.db_name in order to get the database name of a specific site in coding? or is there another way to do that?


they have two ways in this article :
one show where naming db for site happens in code ,
the second show that you can create the name when you create a new-site like this :
bench new-site sitename --db-name database_name

Thanks @ahmadRagheb
but this is not what I mean :slight_smile:

I have read this article previously, but I want to get the database name of any site after installing, I know also it will be in the config file of the site, but i want to use the above command for that

It is very simple, my friend.


returns a Python dictionary with the key pair values contained in the site_config file. With that said then what you just need to do is use the key that you want in order to get its respective value.

So, for your particular case you would use something like this:


Thanks for your replying @yefritavarez
Ok i used the one you mentioned and the other in my post above; it works fine but for the current site; but when i want to determine another one; how can i get it is dbname?

You write a MySQL query like this and it will give you what you need:

frappe.db.sql("""SHOW DATABASES""")

by these command i can not know the site name of every db.
I solved it by generating a function to do that