Documentation Home
MySQL 9.1 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.4Mb
PDF (A4) - 40.5Mb
Man Pages (TGZ) - 259.5Kb
Man Pages (Zip) - 366.7Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.1 Reference Manual  / ...  / Optimization  / Optimizing the MySQL Server  / Using Symbolic Links  /  Using Symbolic Links for Databases on Windows

10.12.2.3 Using Symbolic Links for Databases on Windows

On Windows, symbolic links can be used for database directories. This enables you to put a database directory at a different location (for example, on a different disk) by setting up a symbolic link to it. Use of database symlinks on Windows is similar to their use on Unix, although the procedure for setting up the link differs.

Suppose that you want to place the database directory for a database namedmydb atD:\data\mydb. To do this, create a symbolic link in the MySQL data directory that points toD:\data\mydb. However, before creating the symbolic link, make sure that theD:\data\mydb directory exists by creating it if necessary. If you already have a database directory namedmydb in the data directory, move it toD:\data. Otherwise, the symbolic link has no effect. To avoid problems, make sure that the server is not running when you move the database directory.

On Windows, you can create a symlink using themklink command. This command requires administrative privileges.

  1. Make sure that the desired path to the database exists. For this example, we useD:\data\mydb, and a database namedmydb.

  2. If the database does not already exist, issueCREATE DATABASE mydb in themysql client to create it.

  3. Stop the MySQL service.

  4. Using Windows Explorer or the command line, move the directorymydb from the data directory toD:\data, replacing the directory of the same name.

  5. If you are not already using the command prompt, open it, and change location to the data directory, like this:

    C:\> cd\path\to\datadir

    If your MySQL installation is in the default location, you can use this:

    C:\> cd C:\ProgramData\MySQL\MySQL Server 9.1\Data
  6. In the data directory, create a symlink namedmydb that points to the location of the database directory:

    C:\> mklink /d mydb D:\data\mydb
  7. Start the MySQL service.

After this, all tables created in the databasemydb are created inD:\data\mydb.

Alternatively, on any version of Windows supported by MySQL, you can create a symbolic link to a MySQL database by creating a.sym file in the data directory that contains the path to the destination directory. The file should be nameddb_name.sym, wheredb_name is the database name.

Support for database symbolic links on Windows using.sym files is enabled by default. If you do not need.sym file symbolic links, you can disable support for them by startingmysqld with the--skip-symbolic-links option. To determine whether your system supports.sym file symbolic links, check the value of thehave_symlink system variable using this statement:

SHOW VARIABLES LIKE 'have_symlink';

To create a.sym file symlink, use this procedure:

  1. Change location into the data directory:

    C:\> cd\path\to\datadir
  2. In the data directory, create a text file namedmydb.sym that contains this path name:D:\data\mydb\

    Note

    The path name to the new database and tables should be absolute. If you specify a relative path, the location is relative to themydb.sym file.

After this, all tables created in the databasemydb are created inD:\data\mydb.