is it safe to create mysql database by just creating its directory? context: I want a separate encrypted filesystem per database (to have a separate key) on MySQL 5.7 but if I mount it before  I execute CREATE DATABASE foo it fails with error database exists, and mouting the filesystem after is a bit risky to me.
So I noticed I can &quot;create&quot; a database in MySQL but just creating a folder inside the mysql datadir and creating tables after causes no trouble. I know this is dirty but this way it simplifies the integration with the creation of the filesystem underneath (as it appeared as the folder when lie the tables).
Does creating database this way is safe?
UNSAFE!
Use CREATE DATABASE.

mkdir probably works for ENGINE=MyISAM, but that old engine should not be used anymore.
InnoDB needs to know what is going on.
You noticed db.opt; but what if something else gets added in the future?
MySQL 8.0 has an internal &quot;data dictionary&quot; that would be totally confused by that mkdir.
And who knows what future versions will be like !

It is possible to execute a command on the mysql commandline tool.  This makes CREATE DATABASE a one-liner, albeit more verbose than a simple mkdir.
If you want a table or partition to be on a different physical drive, check out the limited capabilities of specifying the location for the DATA DIRECTORY:  https://dev.mysql.com/doc/refman/8.0/en/innodb-create-table-external.html