0

I know that MySQL/MariaDB can be configured at the system level to use a custom path rather than /var/lib/mysql. This requires restarting the service.

Is there any way to just run a one-off sql command against a given data directory? My use case is a shell script initializing and setting up a directory before creating a Docker container with that directory bind-mounted to the container's MySQL data directory. I don't want this to require changing anything running on the system.

2

I don't think you can switch the data directory during runtime. Sorry about that.

You COULD start another mysqld using another tcp port while handing it another data directory at the command line:

mysqld --port 3307 --socket=/var/run/mysqld/temp-mysqld.sock --datadir /tmp/mysql-data

And then connect to that mysqld and run your query there:

mysql --port 3307 --socket=/var/run/mysqld/temp-mysqld.sock

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.