mysql create database in custom folder

No its not possible .. there is no FOLDER switch for the create database command : http://dev.mysql.com/doc/refman/5.0/en/create-database.html

MySQL uses the folder specified in the my.cnf file for the placement of its files - look for the datadir option in the .cnf file.

Link to the docs for datadir


  1. create a folder on the target drive for the data base you want to create.

  2. make an mlink with the name of the database you want so if db name is db1 :

mklink /d db1 g:\db1data 
  1. on win7 need to start cmd prompt as admin - right click run as administrator.

  2. g:\db1data should exist before running the mlink command and stop mysql before you do this, restart to see the new data base.

  3. just used this to make a db on a RAM drive. Plan to copy it to a disk backed 'normal' db before shutdown!

Reference http://dev.mysql.com/doc/refman/5.6/en/symbolic-links.html

Used tool imdisk with command :

imdisk -a -t vm -m g: -s 2g

To create the RAM disk first.


In Linux environment it can be painless using simple symbolic links:

1) first check in my.cnf [/etc/mysql/my.cnf] for database files destination.
2) let say that destination is in folder /var/lib/mysql/ and yours database name is "abccompany"
3) stop mysql database
4) move folder [var/lib/mysql/abccompany] to new destination (let say "/diskY")
5) make symbolic link:
         ln  -s  /diskY/abccompany   abccompany
6) start mysql database and everything should work just fine.

Tags:

Mysql