How to install and start multiple MySQL instances on Windows 2012
Solution 1:
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
- 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.
Solution 2:
I believe you were trying to run them on the same port.
Changed the ports numbers to be different was what made it work
Solution 3:
- Create a separate data folder and give FULL CONTROL to NETWORK SERVICE.
- Copy the my.ini file to the new data folder.
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]';
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"
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
Start the service
NET START MySQL57-2
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.