0% found this document useful (0 votes)
4 views5 pages

Multiple Mysql Instances On Single Machine

This document provides a step-by-step guide on setting up multiple MySQL instances on a single machine. It outlines the reasons for needing multiple instances, the existing environment setup, and detailed instructions for creating and managing a second MySQL instance. The guide also includes automation tips for easier connection to the instances.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Multiple Mysql Instances On Single Machine

This document provides a step-by-step guide on setting up multiple MySQL instances on a single machine. It outlines the reasons for needing multiple instances, the existing environment setup, and detailed instructions for creating and managing a second MySQL instance. The guide also includes automation tips for easier connection to the instances.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Dost Muhammad Khalil (OCP)

[email protected]
+92 311 4848475

Creating Multiple Mysql Instances on Single Host


Agenda: In this document I will try to deliver the step by step knowledge how to setup two mysql instances on same
machine, in more simple words I will try to let you know how to run two mysql databases on single machine.

Why You need to know about it:

1. If you have time its better to ameliorate your knowledge in your field.
2. In most of the organizations developers require to have tens of mysql instances so in such case infra team is not
ready to provide single machine for those tens of mysql instances separately also doing so is just waste of
resources.

Lab:

Existing Environment:
#Verifying single instance is running.

##checking /etc/my.cnf file for configuration

Setting up environment for the second instance:


#Creating data directory for second instance.

#coping the my.cnf file of the first instance

#updating the copied my2.cnf file to make it ready for the second instance.

23-Jan-2025
Dost Muhammad Khalil (OCP)
[email protected]
+92 311 4848475

#Checking the directory for the second instance which is currently empty.

#initialization of mysqld which creates the necessary files for mysql second instance

#As can be seen after initialization the files are created.

#Starting second Instance

23-Jan-2025
Dost Muhammad Khalil (OCP)
[email protected]
+92 311 4848475

#Verifying Second Instance is running.

#As this is fresh instance so we will have to cat the error log file to get the temporary created password to connect to
the instance and change the password for root.

#Connecting to second instance and change the temporary password for root user.

#Now its difficult to manually differentiate between the instances while connecting to them and checking to them so
that’s why we will create service for the second instance as well which will allow us to connect, check the status as
like the first one instance for which we use “systemctl status mysqld”

#copying the mysqld.service file to mysqld2.service

23-Jan-2025
Dost Muhammad Khalil (OCP)
[email protected]
+92 311 4848475

##append the following two lines in mysqld2.service file if already exists comment out them

#Reload the deamon thread

#mysqld2 can now be used to start,stop and check status for the second instance.

#Now one last thing is to automate the connect with the instances so for this just do the below lines in .bashrc file.

#As can be seen its simple now to connect with the first and the second instance.

23-Jan-2025
Dost Muhammad Khalil (OCP)
[email protected]
+92 311 4848475

23-Jan-2025

You might also like