0

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?

0

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; 
  • That works for your example; I wonder if it always works. The @002e smells like a Unicode codepoint, but with @ instead of U+ or 0x. I'll guess that an emoji in the database name may be tricky. – Rick James Apr 24 at 19:07
0

To know which database you session is connected to, fire below query :

mysql> select database();
+---------------+
| database()    |
+---------------+
| foo       |
+---------------+
1 row in set (0.00 sec)

To fetch path for traversing to schema directory, output from below query can be used :

select concat(VARIABLE_VALUE, database())  from performance_schema.global_variables where variable_name='datadir'; 
+------------------------------------+
| concat(VARIABLE_VALUE, database()) |
+------------------------------------+
| /var/lib/mysql/foo             |
+------------------------------------+
1 row in set (0.00 sec)
  • This is not correct. Create a database called .-OWNED-. – Evan Carroll Apr 24 at 14:21
  • @EvanCarroll - then put that in the Question and emphasize that you have naughty characters in the database name. – Rick James Apr 24 at 18:14
  • @RickJames ok... updated. – Evan Carroll Apr 24 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.