4

Lets say I have 2 databases, "foo" and "bar", and I want MySQL to store "foo" in "/media/foo", and "bar" in "/media/bar", can this be done in MySQL 5.5 or later?

hanshenrik
  • 236
  • 2
  • 13
  • 4
    possible duplicate of http://serverfault.com/questions/158218/can-i-specify-where-my-database-files-are-stored-per-database-in-mysql – Matija Nalis Apr 12 '16 at 19:46

1 Answers1

10

Normally each database is already in a subdirectory of its own. From the manual :

A database in MySQL is implemented as a directory containing files that correspond to tables in the database. Because there are no tables in a database when it is initially created, the CREATE DATABASE statement creates only a directory under the MySQL data directory and the db.opt file.
...
If you manually create a directory under the data directory (for example, with mkdir), the server considers it a database directory and it shows up in the output of SHOW DATABASES.

With InnoDB with the DATA DIRECTORY = absolute_path_to_directory clause of the CREATE TABLE statement you can even create tables outside of the normal MySQL (sub-) directory structures

HBruijn
  • 77,029
  • 24
  • 135
  • 201