Mysql – How to resolve a database name to a directory

mariadbMySQL

I am connected to a database foo, and I want to resolve where the underlying directory is for that database, what are my options? Obviously I can reason from datadir, and the database name but there are problems with that: it requires me to implement my own encode function to map identifiers to file names.. Which is encoding-dependant.

This encoding process is mandatory, the database foo._234-asdf maps to data directory /var/lib/mysql/foo@002e_234@002dasdf.

Is there a supported way to query the data-directory for a specific database, or for the connected database?

Best Answer

I couldn't find a better way of doing this than rolling my own routine. Currently, I am using this perl code:

s/(\W)/sprintf('@%04x', ord $1)/eg;