14

I just installed MySQL 5.7 on Windows 2012 VM. I am trying to create and run multiple instances but very frustrated that such a simple thing is not working.

I installed MySQL in C:\Program Files\MySQL\MySQL Server 5.7 which is default location and then I copied the folder and made another copy of it to create another instance (I suppose this is how it works?)

Both MySQL instances are shown in image below.

Server1 Server1

Server2
Server2

INI settings for both servers are given below:

Server1

server-id=1
log-bin="mysql-bin"
binlog-ignore-db=test
binlog-ignore-db=information_schema
replicate-ignore-db=test
replicate-ignore-db=information_schema
relay-log="mysql-relay-log"
auto-increment-increment = 2
auto-increment-offset = 1

Server2
server-id=2
log-bin="mysql-bin"
binlog-ignore-db=test
binlog-ignore-db=information_schema
replicate-ignore-db=test
replicate-ignore-db=information_schema
relay-log="mysql-relay-log"
auto-increment-increment = 2
auto-increment-offset = 2

I am running both servers by opening command prompt and typing following:
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld"
"C:\Program Files\MySQL\MySQL Server 5.7 - 2\bin\mysqld"

The command seems to run successfully as no error is shown but when I look at task manager to see if any mysql processes are running, I see none.

What am I doing wrong?

5 Answers5

12

The mistake I was doing was to copy whole MySQL installation folder. You don't need to copy this folder.

  • Simply create a new ini file for each instance that you want to run (examples given above) at any location for e.g. C:\MyInstances\my1.ini.
  • Then create a new folder for e.g. data1 in C:\MyInstances\data1 and copy mysql and information_schema databases in it. You will get these databases from data folder where MySQL is installed. On Windows 2012 (and probably other server OS) it typically is C:\ProgramData\MySQL
  • Then define the following in your ini file.

datadir=C:/MyInstances/data1

  1. Then run following command which will install MySQL as service. After services is created simply run the service.

MySqlpath\bin\mysqld --install mysqld1 --defaults-file=PATH_TO_YOUR_INI_FILE

Of course in each ini file, you have to define a different port number as mentioned by @Anthony Fornito.

11

I believe you were trying to run them on the same port.

Changed the ports numbers to be different was what made it work

11
  1. Create a separate data folder and give FULL CONTROL to NETWORK SERVICE.
  2. Copy the my.ini file to the new data folder.
  3. Create a new file in the data directory called mysql-init.txt and add a single line to ensure that the password of the root user is set.

    • ALTER USER 'root'@'localhost' IDENTIFIED BY '[Enter Password]';
  4. Edit the my.ini file by changing the port, socket, datadir, and shared memory base name. All of which need to be different from other instances of MySQL.

my.ini:

[client]
port=3333
socket=MYSQL2_INST.SOCK
shared-memory-base-name=MYSQL2_INST

[mysqld]
shared-memory-base-name=MYSQL2_INST
socket=MYSQL2_INST.SOCK
port=3333
basedir="C:/Program Files/MySQL/MySQL Server 5.7"
datadir="E:/MySQL2/Data"
  1. From the command line navigate to ~\MySQL Server X.Y\bin\ and run

    • mysqld --install MySQL57-2 --defaults-file=E:\mysql2\data\my.ini --init-file=E:\mysql2\data\mysql-init.txt
  2. Start the service

    • NET START MySQL57-2
  3. Check to make sure the service started successfully. If it didn’t then you can find an error log in the data folder else you should be good to go.

1

My steps on Windows 10:

  1. Copy C:\ProgramData\MySQL\MySQL Server 8.0\my.ini to C:\ProgramData\MySQL\MySQL Server 8.0\my1.ini
  2. Open my1.ini and modify:
    • port=3307(under Client and Server Section)
    • datadir=C:/ProgramData/MySQL/MySQL Server 8.0/Data1
    • report_port=3307
  3. Copy C:\ProgramData\MySQL\MySQL Server 8.0\Data to C:\ProgramData\MySQL\MySQL Server 8.0\Data1
  4. Run on cmd prompt: (With Administrator privileges if necessary)
    C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld --install MySQL80-1 --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my1.ini"

If all went well, you will see:
Service successfully installed.

  1. Win+R
    Type services.msc, find the service name MySQL80-1, right-click on it and click Start.

If all went well, you will see the Status change to Running.
If it did not go well, open xxx.err file found in C:\ProgramData\MySQL\MySQL Server 8.0\Data1 to check why.


If you do not want the service anymore:

  • Stop it
  • Delete it on the cmd prompt using sc delete MySQL80-1 where MySQL80-1 is your service name.
0

Things worked slightly different for me. I use mysql 8.0. First i copied the contents of my.ini to my2.ini. In the my2.inin file, i made these changes: under [client]: port=3307

under [mysqld]: port=3307 datadir=C:/ProgramData/MySQL/MySQL Server 8.0\Data2(Data is the default for first instance)

Then open command prompt as administrator at path= "C:\Program Files\MySQL\MySQL Server 8.0\bin" and run the following commands:

mysqld --initialize-insecure --console --datadir="C:\ProgramData\MySQL\MySQL Server 8.0\Data2" (to populate the folder with default mysql tables and files.

mysqld --install MySQL3307 --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my2.ini" (to install mysql server as a windows service).

Go to windows services, run the "MySQL3307" service and you will be good to go.