Start Multiple MySQL Instances

Starting Multiple MySQL Instances at the Windows Command Line

A. Starting Multiple MySQL Instances at the Windows Command Line

To start multiple servers this way, you can specify the appropriate options on the command line or in an option file. It is more convenient to place the options in an option file, but it is necessary to make sure that each server gets its own set of options. To do this, create an option file for each server and tell the server the file name with a --defaults-file option when you run it.

Suppose that you want to run one instance of mysqld on port 3307 with a data directory of D:\xampp\mysql\data1, and another instance on port 3308 with a data directory of D:\xampp\mysql\data2. Use this procedure:

  1. Make sure that each data directory exists, including its own copy of the mysql database that contains the grant tables.
  2. Create two option files. For example, create one file named D:\xampp\mysql\bin\my1.ini that looks like this:
    datadir = D:/xampp/mysql/data1
    port = 3307

    Create a second file named D:\xampp\mysql\bin\my2.ini that looks like this:

    datadir = D:/xampp/mysql/data2
    port = 3308

    Hint: If you copy my1.ini from my.ini, replace all port 3306 to 3308, and D:/xampp/mysql/data to D:/xampp/mysql/data2

  3. Use the --defaults-file option to start each server with its own option file:
    C:\> D:\xampp\mysql\bin\mysqld --defaults-file=D:\xampp\mysql\bin\my1.ini
    C:\> D:\xampp\mysql\bin\mysqld --defaults-file=D:\xampp\mysql\bin\my2.ini

    Each server starts in the foreground (no new prompt appears until the server exits later), so you will need to issue those two commands in separate console windows.

  4. To shut down the servers, connect to each using the appropriate port number:
    C:\> D:\xampp\mysql\bin\mysqladmin --port=3307 --host= --user=root --password shutdown
    C:\> D:\xampp\mysql\bin\mysqladmin --port=3308 --host= --user=root --password shutdown

B. Starting MySQL as a Windows Service

C:\> D:\xampp\mysql\bin\mysqld --install mysql1 --defaults-file=D:\xampp\mysql\bin\my1.ini
C:\> D:\xampp\mysql\bin\mysqld --install mysql2 --defaults-file=D:\xampp\mysql\bin\my2.ini
C:\> D:\xampp\mysql\bin\mysqld --install mysql3 --defaults-file=D:\xampp\mysql\bin\my3.ini
C:\> net start mysql1
C:\> net stop mysql1
C:\> sc delete mysql1


Popular posts from this blog