SlideShare a Scribd company logo
1 of 36
INDEX
A. MySQL Mater-Slave and Master-Master Replication; Step by Step configuration
instructions
B. Setting up MySQL Master-Slave Replication
C. Second Method to implementation for master-slave replication on
MySQL
D. MySQL Master- Master Replication
(A)MySQL master-slave and master-master replication. Step by step
configurationinstructions:
If you are looking for the options to scale your MySQL installation you may be also
interested in MySQL partitioning and sub partitioning. It may improve each node speed
and capacity parameters.
One may say that there are a lot of MySQL replication manuals, but latest versions of
MySQL server have changed the way how configuration should be applied. Most of the
manuals do not reflect these changes.
Just want to mention that this technique is usually used for load balancing on database
servers. If you have a lot of read requests (most common for web applications) master-
slave replication should suit your needs well.
In this case you will do write transactions on master host and read requests on slave
hosts, because data is populated from master to slave much faster than from slaves to
master and to other slaves.
But sometimes you might have more write requests or may have other (application
related) reasons to start another type of replication. You can see it on the next figure and
that is so called master-master replication.
In this article I will describe simple master-slave architecture with 2 hosts and simple
master-master replication with the same 2 hosts. Our final goal is to configure master-
master replication, what includes several sub-steps, so let’s start. Sure you should
configure network services on both systems.
(B) Setting up MySQL Master-Slave Replication :
This article is about setting up MySQL Master-Slave replication between two Cloud
Servers.
Setup Outline:
For the purpose of this scenario, we will have two Servers, named INVIRH54DB3
and INVIRH54DB2. These Servers have two IP addresses. For the duration of the
scenario INVIRH54DB3 (10.65.43.200) is considered master MySQL server
(running in read-write mode), and INVIRH54DB2 (10.65.42.199) is considered the
slave (running in read-only mode).
If you already have a MySQL database running on the master node, a dump and
restore into the slave would be required into the slave node before configuring
replication between them. We will be using the mysqldumpcommand to dump a
database into a file, transferring it and restoring it to the slave. Once the necessary
configuration has been carried out, replication will be in effect from that point
onwards.
Step: 1 Install MySQL in two machines.
Step: 2 Configuration of master server
Configure your Servers:
Master: (INVIRH54DB3)
You'll need to edit the my.cnf file on the Master server to enable binary logging and set
the server's id.
Like: Add these lines under the [mysqld] section:
This will enable binary logging and set the Master's server-id to '1'. Restart MySQL for the
changes to take effect. Then we restart MySQL.
Master my.cnf configuration done.
Slave (INVIRH54DB2)
You'll need to edit the my.cnf file on the Slave server to set the server's id to something
different than the master.
Add these lines under the [mysqld] section.This assign the Slave a unique server-id. Now
let’s restart MySQL so these changes take effect.
Slave my.cnf configuration done.
Step: 3 Taking Backup on Mater Server
In Master side we have following databases:
In Slave side we have following databases:
Next apply READ LOCK to databases to export all the database and master database
information with mysqldump command.
Grab the Master Information:
On the Master server, we'll need to find out the binary log it is currently using and the
position it is at in that binary log. If you haven't logged out of MySQL from creating that
replication user, you should be at the MySQL prompt already. Go ahead and lock the
tables so we can safely grab that data.
Log into the master server.
Command :FLUSH TABLES WITH READ LOCK;
After giving “FLUSH TABLES WITH READ LOCK” Command on master server, we need to
take full back up on master server by using following command.
# mysqldump -u root -p --all-databases --master-data > /root/dbdump.db
Or
# mysqldump -u root -p --databases sample1 sample2 sample3 > /tmp/masterdata.sql
Once you’ve dump all the databases, now again connect to mysql as root user and unlcok
tables.
mysql> UNLOCK TABLES;
mysql> quit;
Step: 4 Creating a Replication User (In Master Server)
The Slave server will connect to the Master via a standard MySQL user and password.
This user will need to have been granted the 'REPLICATION SLAVE' privilege. Let's create
that user on the Master server now.
You should be at the mysql prompt on the Master server. Once there, let's create a new
user and grant him the proper privilege.
This statement is basically saying grant the ‘replication’ user replication slave access to
any database/table on this host from the Slave server's private IP. Now tell the server to
reload the grant tables with the statement 'FLUSH PRIVILEGES'.
At this point, it's a good idea to make sure you're able to access the Master from the
Slave using the credentials you just created. Alright, now back to the Slave server.
Here password is replication
Be sure to use your private IP for your Master server. In this example, mine is
10.65.43.200. Do you get a MySQL prompt? If so, you're successfully logged into your
Master server using the new 'replication' user you just created. Alright, we're about half
way there.
Upload the database dump file from master server to Slave Server (10.65.42.199) using
SCP command.
Command: scp /tmp/masterdata.sqlteradata@10.65.42.199:/tmp/
Now we need to check that file copied or not on slave side
Step: 5 Import to the Databases on slave side
Now import the dump file that we exported in earlier command and restart the MySQL
service.
Before importing DB’s on slave server :
Commandis : (For importing)
[root@INVIRH54DB2 ~]# mysql -u root -p < /tmp/masterdata.sql
Enter password:
Here password is mysql
This time to check all databases are imported or not in slave server
Earlier we have only 4 databases in slave server, after importing DB’s from dump file we
get 7 databases.
Step: 6 Check the Mater Status (On Master Server)
Note the current binary log and position. In our example, the Master server is currently
on the mysql-bin.00002 binary log and is at position 347.
Now we'll use the 'SHOW MASTER STATUS' command to get all the data we need.
Step: 7Final Slave Config: (In Slave server)
Changing the Master Information on the Slave:
Up to this point, you should have collected the following information:
Private IPs
replication username and password
Master server binary log and position.
Now it's time to use this information to connect the Slave server to the Master server.
Let's start configuring the Slave.
Restart the MySQL service. (Slave Server)
# /etc/init.d/mysqld restart
Once at the mysql prompt, we're going to change the Master information with the
'CHANGE MASTER TO' statement (so the Slave server knows where/how it's connecting).
Note the values for each field. The MASTER_HOST is the private IP of the Master server,
MASTER_USER is the user we created for replication, MASTER_PASSWORD is the
password for the replication user, MASTER_LOG_FILE is the binary log that we recorded
from the Master server status earlier, and MASTER_LOG_POS is the position the Master
was in that we recorded.
Step: 8Start the Slave Thread (In Slave Server)
Ok, now start the slave thread on the Slave server.
Let’s make sure that replication is working with the 'SHOW SLAVE STATUS' statement.
(In Slave Server)
If you see that Slave_IO_State is 'Waiting for master to send event' and
Seconds_Behind_Master isn't 'NULL', your replication is working! If it does show NULL,
go back and double check your 'CHANGE MASTER TO'statement to make sure all data is
correct. That's it...
Step: 9Testing scenarios
For the purpose of testing our replication setup, we can create a new database
(SAMPLE4) and associated table (EMP3) on INVIRH54DB3 (Master), inserting data to
confirm that the changes are mirrored on INVIRH54DB2. Here is an example:
In Mater server:
The changes should be visible on INVIRH54DB2 immediately.
In Slave server:
In Case if the master is go down stage :
In Slave need to check whether database and tables are accessible or not?
The slave server is never down.
To see the server_ids on the mysql prompt type this command :
Mysql> show variables like '%server%id';
(C)This is the Second way to implementation on master-slave replication
onmysql:
Database replication is possible under MySQL via binary logging. This is a log over all
changes that are done to a particular database configured in/etc/mysql/my.cnf.
This "change log" is then shared with another MySQL server (the slave) which is the kept
in a synchronous state. First we need to install bothon MySQL servers.
In my Scenario,
Let us assume: INVIRH54DB3 -10.65.43.200 ------ MasterAnd
INVIRH54DB2 – 10.65.42.199 ----- Slave
INVIRH54DB3
(MASTER)
INVIRH54DB2
(SLAVE)
Step: 1 Configuration of master server
On the master:Edit vi /etc/my.cnf
#bind-address = 127.0.0.1
Server-id = 1
Log-bin = /var/lib/mysql/mysql-bin.log
Expire-logs-days = 20
max_binlog_size = 104857600
Binlog-do-db = testdatabase
Binlog-ignore-db = MySQL, test,sample4
We need to disable bind-address (slave needs to talk to master via the interface).
Furthermore we tell the master that it is server 1 and that we want replication of
database testdatabase, but not mysql and test.
Then we restart MySQL:/etc/init.d/mysql restart
Then we log into the MySQL database as root and create a user with replication
privileges:
Step: 2 Configuration of slave server
mysql> create database testdatabase;
Now we have to tell MySQL on the slave that it is the slave, that the master is
10.65.43.200, and that the master database to watch is testdatabase. Therefore we add
the following lines to /etc/mysql/my.cnf:
Then we restart MySQL.
/etc/init.d/mysql restart
From MySQL on the slave the master must be configured as well. Here the
MASTER_LOG_FILE value of mysql-bin.000004 and the MASTER_LOG_POS value
of 197 are the values acquired from the SHOW MASTER STATUS on the master.
If you are facing any issue like this
Solution:
ERROR 1200(HY00) :The server is not configured as slave ;fix in config file or with
CHANGES MASTER TO
So, you have restarted mysqld, and the slave did not start. You issue SHOW SLAVE
STATUSG and notice that everything is fine but “Slave_IO_Running” and
“Slave_SQL_Running” both say “No” .
This has happened to me numerous throughout my time administering mysql servers.
The variable server_id always need to be set to something when running replication.
Check if server_id is set by using “SHOW VARIABLES LIKE ‘server_id;”.
The value should be “0” or “1”.”1” is normally set by default.Also,the master’s server_id
and the slave’s server_id should not be the same. You can set server id by using “SET
GLOBAL server_id=;” then issue a START SLAVE;we should be fine now…
Step: 3 Testing the setup
Table creation
On Master
CREATE TABLE example (id INT, dataVARCHAR (100));
On slave: Check,
MySQL>SHOW TABLES;
--Write test:On Master
On Slave:Before inserting rows.
After inserting rows from master to slave:
In Case of Master is down:
On Slave:
(D) MySQL Master- Master Replication:
This tutorial describes how to set up MySQL master-master replication. We need to
replicate MySQL servers to achieve high-availability (HA). In my case I need two masters
that are synchronized with each other so that if one of them drops down, other could
take over and no data is lost. Similarly when the first one goes up again, it will still be
used as slave for the live one.
Here is a basic step by step tutorial that will cover the MySQL master and master
replication.
Note:
We will call system 1 as master1 and slave2 and system2 as master2 and slave 1.
Step 1:
Install MySQL on master 1 and slave 1. Configure network services on both systems, like
Master 1/Slave 2 ip: 10.65.43.200 (INVIRH54DB3)
Master 2/Slave 1 ip : 10.65.42.199 (INVIRH54DB2)
Step 2:
On Master 1, make changes in my.cnf:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
old_passwords=1
log-bin
binlog-do-db=<database name> # input the database which should be replicated
binlog-ignore-db=mysql # input the database that should be ignored for replication
binlog-ignore-db=test
server-id=1
[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Step 3:
On master 1, create a replication slave account in MySQL.
MySQL> grant replication slave on *.* to ‘replication’@10.65.42.199 identified by
'replication';
And restart the MySQL master1.
Step 4:
Now edit my.cnf on Slave1 or Master2:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
old_passwords=1
Server-id=2
master-host = 192.168.16.4
master-user = replication
master-password = slave
master-port = 3306
[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Step 5:
Restart MySQL slave 1 and at
MySQL> start slave;
MySQL> show slave statusG;
Above highlighted rows must be indicating related log files and Slave_IO_Running and
Slave_SQL_Running: must be to YES.
Step 6:
On master 1:
MySQL> show master status;
The above scenario is for master-slave, now we will create a slave master scenario for
the same systems and it will work as master-master.
Step : 7
On Master2/Slave 1, edit my.cnf and master entries into it: (10.65.42.199)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
server-id=2
master-host = 10.65.43.200
master-user = replication
master-password = slave
master-port = 3306
log-bin #information for becoming master added
binlog-do-db=mysql
[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Step 8:
Create a replication slave account on master2 for master1:
MySQL> grant replication slave on *.* to 'replication'@10.65.43.200 identified by
'slave2';
Step 9:
Edit my.cnf on master1 for information of its master. (INVIRH54DB3)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
log-bin
binlog-do-db=mysql
server-id=1#information for becoming slave.
master-host = 10.65.42.199
master-user = replication
master-password = slave2
master-port = 3306
Step 10:
Restart both MySQL master1 and master2.
On MySQL master1:
mysql> start slave;
On mysql master2:
mysql> show master status;
On mysql master 1:
mysql> show slave statusG;
@@@@@@@@@@@@@@@@@@@@@@@
To setup Master and Slave Replication:
Master to Slave Replication:
In Master Server
1. After installing mysql in master server. below are the steps to do
cd /etc/mysql/
cpmy.cnf my.cnf_bkf_`date +%F`
vim my.cnf
uncommentlog_bin variable(To enable Binary logs)
setserver_id = 1 ---- should be unique
uncommentbind_address variable
Save changes and restart the mysql service (/etc/init.d/mysql restart)
In Slave Server
2. After installing mysql in slave server. below are the steps to do
cd /etc/mysql/
cpmy.cnf my.cnf_bkf_`date +%F`
vim my.cnf
setserver_id = 2 ---- should be unique
Save changes and restart the mysql service (/etc/init.d/mysql restart)
In Master Server
3. Full Backup Process
Open one terminal and
Flush tables with read lock; (Do not quit the server until the full backup process(Step
4) completes )
show master status; (Copy log file name and position)
4. Open another terminal and login to master (Do not exit the previous terminal)
mysqldump -u root -ppadnet --all-databases >fullbackup_`date +%F`.sql
5. Now go to 1st terminal and
unlock tables;
exit;
6. Move the full backup to slave using scp command
scp -Pportno(ifany) filename username@ip:/path
7. In Master
GRANT REPLICATION SLAVE ON *.* TO repuser@'slaveip' identified by 'password';
FLUSH PRIVILEGES;
8.Login to slave
mysql -u root -ppadnet<filename.sql
CHANGE MASTER TO
master_host='master_ip_addresss',master_password='password',master_user='repuser',
master_log_file='log file name',master_log_pos=pos;
FLUSH PRIVILEGES;
start slave;
show slave statusG
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
DB3
mysql> insert into user(host,user,password,select_priv) values
('%','root',password('mysql'),'Y');
ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
Db2
mysql> insert into user(host,user,password,select_priv) values
('%','root',password('mysql'),'Y');
Query OK, 1 row affected, 3 warnings (0.00 sec)
http://www.tecmint.com/how-to-setup-mysql-master-slave-replication-in-rhel-centos-fedora/

More Related Content

What's hot

MySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesMySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesLenz Grimmer
 
Introduction to MariaDB MaxScale
Introduction to MariaDB MaxScaleIntroduction to MariaDB MaxScale
Introduction to MariaDB MaxScaleI Goo Lee
 
Maxscale_메뉴얼
Maxscale_메뉴얼Maxscale_메뉴얼
Maxscale_메뉴얼NeoClova
 
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale  by ...[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale  by ...
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...Insight Technology, Inc.
 
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015Dave Stokes
 
Mysql high availability and scalability
Mysql high availability and scalabilityMysql high availability and scalability
Mysql high availability and scalabilityyin gong
 
Getting started with my sql
Getting started with my sqlGetting started with my sql
Getting started with my sqlWeb Sky
 
Percona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient BackupsPercona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient BackupsMydbops
 
MySQL Replication: Demo Réplica en Español
MySQL Replication: Demo Réplica en EspañolMySQL Replication: Demo Réplica en Español
MySQL Replication: Demo Réplica en EspañolKeith Hollman
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group ReplicationManish Kumar
 
Meb Backup & Recovery Performance
Meb Backup & Recovery PerformanceMeb Backup & Recovery Performance
Meb Backup & Recovery PerformanceKeith Hollman
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLKenny Gryp
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016Dave Stokes
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloudTahsin Hasan
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016Dave Stokes
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document StoreDave Stokes
 
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesA26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesInsight Technology, Inc.
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Chris Barber
 
MySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELKMySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELKI Goo Lee
 

What's hot (20)

MySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesMySQL Backup and Security Best Practices
MySQL Backup and Security Best Practices
 
Introduction to MariaDB MaxScale
Introduction to MariaDB MaxScaleIntroduction to MariaDB MaxScale
Introduction to MariaDB MaxScale
 
Maxscale_메뉴얼
Maxscale_메뉴얼Maxscale_메뉴얼
Maxscale_메뉴얼
 
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale  by ...[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale  by ...
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
 
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
 
Mysql high availability and scalability
Mysql high availability and scalabilityMysql high availability and scalability
Mysql high availability and scalability
 
Getting started with my sql
Getting started with my sqlGetting started with my sql
Getting started with my sql
 
Percona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient BackupsPercona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient Backups
 
MySQL Replication: Demo Réplica en Español
MySQL Replication: Demo Réplica en EspañolMySQL Replication: Demo Réplica en Español
MySQL Replication: Demo Réplica en Español
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
Meb Backup & Recovery Performance
Meb Backup & Recovery PerformanceMeb Backup & Recovery Performance
Meb Backup & Recovery Performance
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQL
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document Store
 
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesA26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
 
Mysql
Mysql Mysql
Mysql
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)
 
MySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELKMySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELK
 

Similar to Mater,slave on mysql

MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAHarry Gonzalez
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replicationPoguttuezhiniVP
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group ReplicationDave Stokes
 
Download presentation
Download presentationDownload presentation
Download presentationwebhostingguy
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016Dave Stokes
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestratorYoungHeon (Roy) Kim
 
Setting up MySQL Replication Cluster in Kubernetes
Setting up MySQL Replication Cluster in KubernetesSetting up MySQL Replication Cluster in Kubernetes
Setting up MySQL Replication Cluster in KubernetesElizabeth Yu, MBA
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017Dave Stokes
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroupJayant Chutke
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & clusterelliando dias
 
How to deploy a MariaDB Galera cluster on Ubuntu 14.04
How to deploy a MariaDB Galera cluster on Ubuntu 14.04How to deploy a MariaDB Galera cluster on Ubuntu 14.04
How to deploy a MariaDB Galera cluster on Ubuntu 14.04VEXXHOST Private Cloud
 

Similar to Mater,slave on mysql (20)

MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USA
 
MySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs WeatherlyMySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs Weatherly
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
 
Mysql
MysqlMysql
Mysql
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
Download presentation
Download presentationDownload presentation
Download presentation
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
Setting up MySQL Replication Cluster in Kubernetes
Setting up MySQL Replication Cluster in KubernetesSetting up MySQL Replication Cluster in Kubernetes
Setting up MySQL Replication Cluster in Kubernetes
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 
Mysql S&M
Mysql S&MMysql S&M
Mysql S&M
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
Scalr Demo
Scalr DemoScalr Demo
Scalr Demo
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroup
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & cluster
 
Maria db
Maria dbMaria db
Maria db
 
Sql installation
Sql installationSql installation
Sql installation
 
How to deploy a MariaDB Galera cluster on Ubuntu 14.04
How to deploy a MariaDB Galera cluster on Ubuntu 14.04How to deploy a MariaDB Galera cluster on Ubuntu 14.04
How to deploy a MariaDB Galera cluster on Ubuntu 14.04
 
Mysql-Basics.pptx
Mysql-Basics.pptxMysql-Basics.pptx
Mysql-Basics.pptx
 
Database Replication
Database ReplicationDatabase Replication
Database Replication
 

More from Vasudeva Rao

Inno db datafiles backup and retore
Inno db datafiles backup and retoreInno db datafiles backup and retore
Inno db datafiles backup and retoreVasudeva Rao
 
Convert language latin1 to utf8 on mysql
Convert language latin1 to utf8 on mysqlConvert language latin1 to utf8 on mysql
Convert language latin1 to utf8 on mysqlVasudeva Rao
 
Database migration
Database migrationDatabase migration
Database migrationVasudeva Rao
 
Performence tuning
Performence tuningPerformence tuning
Performence tuningVasudeva Rao
 
All types of backups and restore
All types of backups and restoreAll types of backups and restore
All types of backups and restoreVasudeva Rao
 
Multiple instances second method
Multiple instances second methodMultiple instances second method
Multiple instances second methodVasudeva Rao
 
Multiple instance on windows
Multiple instance on windowsMultiple instance on windows
Multiple instance on windowsVasudeva Rao
 
Multiple instances on linux
Multiple instances on linuxMultiple instances on linux
Multiple instances on linuxVasudeva Rao
 
Postgre sql run book
Postgre sql run bookPostgre sql run book
Postgre sql run bookVasudeva Rao
 

More from Vasudeva Rao (10)

Inno db datafiles backup and retore
Inno db datafiles backup and retoreInno db datafiles backup and retore
Inno db datafiles backup and retore
 
Convert language latin1 to utf8 on mysql
Convert language latin1 to utf8 on mysqlConvert language latin1 to utf8 on mysql
Convert language latin1 to utf8 on mysql
 
Ddl commands
Ddl commandsDdl commands
Ddl commands
 
Database migration
Database migrationDatabase migration
Database migration
 
Performence tuning
Performence tuningPerformence tuning
Performence tuning
 
All types of backups and restore
All types of backups and restoreAll types of backups and restore
All types of backups and restore
 
Multiple instances second method
Multiple instances second methodMultiple instances second method
Multiple instances second method
 
Multiple instance on windows
Multiple instance on windowsMultiple instance on windows
Multiple instance on windows
 
Multiple instances on linux
Multiple instances on linuxMultiple instances on linux
Multiple instances on linux
 
Postgre sql run book
Postgre sql run bookPostgre sql run book
Postgre sql run book
 

Recently uploaded

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Mater,slave on mysql

  • 1. INDEX A. MySQL Mater-Slave and Master-Master Replication; Step by Step configuration instructions B. Setting up MySQL Master-Slave Replication C. Second Method to implementation for master-slave replication on MySQL D. MySQL Master- Master Replication
  • 2. (A)MySQL master-slave and master-master replication. Step by step configurationinstructions: If you are looking for the options to scale your MySQL installation you may be also interested in MySQL partitioning and sub partitioning. It may improve each node speed and capacity parameters. One may say that there are a lot of MySQL replication manuals, but latest versions of MySQL server have changed the way how configuration should be applied. Most of the manuals do not reflect these changes. Just want to mention that this technique is usually used for load balancing on database servers. If you have a lot of read requests (most common for web applications) master- slave replication should suit your needs well. In this case you will do write transactions on master host and read requests on slave hosts, because data is populated from master to slave much faster than from slaves to master and to other slaves. But sometimes you might have more write requests or may have other (application related) reasons to start another type of replication. You can see it on the next figure and that is so called master-master replication.
  • 3. In this article I will describe simple master-slave architecture with 2 hosts and simple master-master replication with the same 2 hosts. Our final goal is to configure master- master replication, what includes several sub-steps, so let’s start. Sure you should configure network services on both systems. (B) Setting up MySQL Master-Slave Replication : This article is about setting up MySQL Master-Slave replication between two Cloud Servers. Setup Outline: For the purpose of this scenario, we will have two Servers, named INVIRH54DB3 and INVIRH54DB2. These Servers have two IP addresses. For the duration of the scenario INVIRH54DB3 (10.65.43.200) is considered master MySQL server (running in read-write mode), and INVIRH54DB2 (10.65.42.199) is considered the slave (running in read-only mode). If you already have a MySQL database running on the master node, a dump and restore into the slave would be required into the slave node before configuring replication between them. We will be using the mysqldumpcommand to dump a database into a file, transferring it and restoring it to the slave. Once the necessary configuration has been carried out, replication will be in effect from that point onwards. Step: 1 Install MySQL in two machines. Step: 2 Configuration of master server Configure your Servers: Master: (INVIRH54DB3) You'll need to edit the my.cnf file on the Master server to enable binary logging and set the server's id. Like: Add these lines under the [mysqld] section:
  • 4. This will enable binary logging and set the Master's server-id to '1'. Restart MySQL for the changes to take effect. Then we restart MySQL. Master my.cnf configuration done. Slave (INVIRH54DB2) You'll need to edit the my.cnf file on the Slave server to set the server's id to something different than the master.
  • 5. Add these lines under the [mysqld] section.This assign the Slave a unique server-id. Now let’s restart MySQL so these changes take effect. Slave my.cnf configuration done.
  • 6. Step: 3 Taking Backup on Mater Server In Master side we have following databases: In Slave side we have following databases: Next apply READ LOCK to databases to export all the database and master database information with mysqldump command. Grab the Master Information: On the Master server, we'll need to find out the binary log it is currently using and the position it is at in that binary log. If you haven't logged out of MySQL from creating that replication user, you should be at the MySQL prompt already. Go ahead and lock the tables so we can safely grab that data. Log into the master server.
  • 7. Command :FLUSH TABLES WITH READ LOCK; After giving “FLUSH TABLES WITH READ LOCK” Command on master server, we need to take full back up on master server by using following command. # mysqldump -u root -p --all-databases --master-data > /root/dbdump.db Or # mysqldump -u root -p --databases sample1 sample2 sample3 > /tmp/masterdata.sql Once you’ve dump all the databases, now again connect to mysql as root user and unlcok tables. mysql> UNLOCK TABLES; mysql> quit;
  • 8. Step: 4 Creating a Replication User (In Master Server) The Slave server will connect to the Master via a standard MySQL user and password. This user will need to have been granted the 'REPLICATION SLAVE' privilege. Let's create that user on the Master server now. You should be at the mysql prompt on the Master server. Once there, let's create a new user and grant him the proper privilege. This statement is basically saying grant the ‘replication’ user replication slave access to any database/table on this host from the Slave server's private IP. Now tell the server to reload the grant tables with the statement 'FLUSH PRIVILEGES'.
  • 9. At this point, it's a good idea to make sure you're able to access the Master from the Slave using the credentials you just created. Alright, now back to the Slave server. Here password is replication Be sure to use your private IP for your Master server. In this example, mine is 10.65.43.200. Do you get a MySQL prompt? If so, you're successfully logged into your Master server using the new 'replication' user you just created. Alright, we're about half way there. Upload the database dump file from master server to Slave Server (10.65.42.199) using SCP command. Command: scp /tmp/masterdata.sqlteradata@10.65.42.199:/tmp/
  • 10. Now we need to check that file copied or not on slave side Step: 5 Import to the Databases on slave side Now import the dump file that we exported in earlier command and restart the MySQL service. Before importing DB’s on slave server : Commandis : (For importing) [root@INVIRH54DB2 ~]# mysql -u root -p < /tmp/masterdata.sql Enter password: Here password is mysql
  • 11. This time to check all databases are imported or not in slave server Earlier we have only 4 databases in slave server, after importing DB’s from dump file we get 7 databases. Step: 6 Check the Mater Status (On Master Server) Note the current binary log and position. In our example, the Master server is currently on the mysql-bin.00002 binary log and is at position 347. Now we'll use the 'SHOW MASTER STATUS' command to get all the data we need.
  • 12. Step: 7Final Slave Config: (In Slave server) Changing the Master Information on the Slave: Up to this point, you should have collected the following information: Private IPs replication username and password Master server binary log and position. Now it's time to use this information to connect the Slave server to the Master server. Let's start configuring the Slave. Restart the MySQL service. (Slave Server) # /etc/init.d/mysqld restart
  • 13. Once at the mysql prompt, we're going to change the Master information with the 'CHANGE MASTER TO' statement (so the Slave server knows where/how it's connecting). Note the values for each field. The MASTER_HOST is the private IP of the Master server, MASTER_USER is the user we created for replication, MASTER_PASSWORD is the password for the replication user, MASTER_LOG_FILE is the binary log that we recorded from the Master server status earlier, and MASTER_LOG_POS is the position the Master was in that we recorded. Step: 8Start the Slave Thread (In Slave Server) Ok, now start the slave thread on the Slave server. Let’s make sure that replication is working with the 'SHOW SLAVE STATUS' statement. (In Slave Server)
  • 14. If you see that Slave_IO_State is 'Waiting for master to send event' and Seconds_Behind_Master isn't 'NULL', your replication is working! If it does show NULL, go back and double check your 'CHANGE MASTER TO'statement to make sure all data is correct. That's it...
  • 15. Step: 9Testing scenarios For the purpose of testing our replication setup, we can create a new database (SAMPLE4) and associated table (EMP3) on INVIRH54DB3 (Master), inserting data to confirm that the changes are mirrored on INVIRH54DB2. Here is an example: In Mater server: The changes should be visible on INVIRH54DB2 immediately.
  • 16. In Slave server: In Case if the master is go down stage : In Slave need to check whether database and tables are accessible or not?
  • 17. The slave server is never down. To see the server_ids on the mysql prompt type this command : Mysql> show variables like '%server%id';
  • 18. (C)This is the Second way to implementation on master-slave replication onmysql: Database replication is possible under MySQL via binary logging. This is a log over all changes that are done to a particular database configured in/etc/mysql/my.cnf. This "change log" is then shared with another MySQL server (the slave) which is the kept in a synchronous state. First we need to install bothon MySQL servers. In my Scenario, Let us assume: INVIRH54DB3 -10.65.43.200 ------ MasterAnd INVIRH54DB2 – 10.65.42.199 ----- Slave INVIRH54DB3 (MASTER) INVIRH54DB2 (SLAVE)
  • 19. Step: 1 Configuration of master server On the master:Edit vi /etc/my.cnf #bind-address = 127.0.0.1 Server-id = 1 Log-bin = /var/lib/mysql/mysql-bin.log Expire-logs-days = 20 max_binlog_size = 104857600 Binlog-do-db = testdatabase Binlog-ignore-db = MySQL, test,sample4 We need to disable bind-address (slave needs to talk to master via the interface). Furthermore we tell the master that it is server 1 and that we want replication of database testdatabase, but not mysql and test. Then we restart MySQL:/etc/init.d/mysql restart
  • 20. Then we log into the MySQL database as root and create a user with replication privileges:
  • 21. Step: 2 Configuration of slave server mysql> create database testdatabase; Now we have to tell MySQL on the slave that it is the slave, that the master is 10.65.43.200, and that the master database to watch is testdatabase. Therefore we add the following lines to /etc/mysql/my.cnf: Then we restart MySQL. /etc/init.d/mysql restart
  • 22. From MySQL on the slave the master must be configured as well. Here the MASTER_LOG_FILE value of mysql-bin.000004 and the MASTER_LOG_POS value of 197 are the values acquired from the SHOW MASTER STATUS on the master. If you are facing any issue like this Solution: ERROR 1200(HY00) :The server is not configured as slave ;fix in config file or with CHANGES MASTER TO So, you have restarted mysqld, and the slave did not start. You issue SHOW SLAVE STATUSG and notice that everything is fine but “Slave_IO_Running” and “Slave_SQL_Running” both say “No” . This has happened to me numerous throughout my time administering mysql servers. The variable server_id always need to be set to something when running replication. Check if server_id is set by using “SHOW VARIABLES LIKE ‘server_id;”. The value should be “0” or “1”.”1” is normally set by default.Also,the master’s server_id and the slave’s server_id should not be the same. You can set server id by using “SET GLOBAL server_id=;” then issue a START SLAVE;we should be fine now…
  • 23. Step: 3 Testing the setup Table creation On Master CREATE TABLE example (id INT, dataVARCHAR (100)); On slave: Check, MySQL>SHOW TABLES;
  • 24. --Write test:On Master On Slave:Before inserting rows. After inserting rows from master to slave:
  • 25. In Case of Master is down: On Slave: (D) MySQL Master- Master Replication: This tutorial describes how to set up MySQL master-master replication. We need to replicate MySQL servers to achieve high-availability (HA). In my case I need two masters that are synchronized with each other so that if one of them drops down, other could take over and no data is lost. Similarly when the first one goes up again, it will still be used as slave for the live one. Here is a basic step by step tutorial that will cover the MySQL master and master replication. Note: We will call system 1 as master1 and slave2 and system2 as master2 and slave 1.
  • 26. Step 1: Install MySQL on master 1 and slave 1. Configure network services on both systems, like Master 1/Slave 2 ip: 10.65.43.200 (INVIRH54DB3) Master 2/Slave 1 ip : 10.65.42.199 (INVIRH54DB2) Step 2: On Master 1, make changes in my.cnf: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock old_passwords=1 log-bin binlog-do-db=<database name> # input the database which should be replicated binlog-ignore-db=mysql # input the database that should be ignored for replication binlog-ignore-db=test server-id=1 [mysqld_safe] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
  • 27. Step 3: On master 1, create a replication slave account in MySQL. MySQL> grant replication slave on *.* to ‘replication’@10.65.42.199 identified by 'replication'; And restart the MySQL master1.
  • 28. Step 4: Now edit my.cnf on Slave1 or Master2: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock old_passwords=1 Server-id=2 master-host = 192.168.16.4 master-user = replication master-password = slave master-port = 3306 [mysqld_safe] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid Step 5: Restart MySQL slave 1 and at MySQL> start slave; MySQL> show slave statusG;
  • 29.
  • 30. Above highlighted rows must be indicating related log files and Slave_IO_Running and Slave_SQL_Running: must be to YES.
  • 31. Step 6: On master 1: MySQL> show master status; The above scenario is for master-slave, now we will create a slave master scenario for the same systems and it will work as master-master. Step : 7 On Master2/Slave 1, edit my.cnf and master entries into it: (10.65.42.199) [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 server-id=2 master-host = 10.65.43.200 master-user = replication master-password = slave master-port = 3306 log-bin #information for becoming master added binlog-do-db=mysql
  • 32. [mysqld_safe] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid Step 8: Create a replication slave account on master2 for master1: MySQL> grant replication slave on *.* to 'replication'@10.65.43.200 identified by 'slave2'; Step 9: Edit my.cnf on master1 for information of its master. (INVIRH54DB3) [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 log-bin binlog-do-db=mysql server-id=1#information for becoming slave. master-host = 10.65.42.199 master-user = replication master-password = slave2 master-port = 3306
  • 33. Step 10: Restart both MySQL master1 and master2. On MySQL master1: mysql> start slave;
  • 34. On mysql master2: mysql> show master status; On mysql master 1: mysql> show slave statusG; @@@@@@@@@@@@@@@@@@@@@@@ To setup Master and Slave Replication: Master to Slave Replication: In Master Server 1. After installing mysql in master server. below are the steps to do cd /etc/mysql/ cpmy.cnf my.cnf_bkf_`date +%F` vim my.cnf uncommentlog_bin variable(To enable Binary logs) setserver_id = 1 ---- should be unique uncommentbind_address variable Save changes and restart the mysql service (/etc/init.d/mysql restart) In Slave Server 2. After installing mysql in slave server. below are the steps to do cd /etc/mysql/ cpmy.cnf my.cnf_bkf_`date +%F` vim my.cnf setserver_id = 2 ---- should be unique Save changes and restart the mysql service (/etc/init.d/mysql restart) In Master Server
  • 35. 3. Full Backup Process Open one terminal and Flush tables with read lock; (Do not quit the server until the full backup process(Step 4) completes ) show master status; (Copy log file name and position) 4. Open another terminal and login to master (Do not exit the previous terminal) mysqldump -u root -ppadnet --all-databases >fullbackup_`date +%F`.sql 5. Now go to 1st terminal and unlock tables; exit; 6. Move the full backup to slave using scp command scp -Pportno(ifany) filename username@ip:/path 7. In Master GRANT REPLICATION SLAVE ON *.* TO repuser@'slaveip' identified by 'password'; FLUSH PRIVILEGES; 8.Login to slave mysql -u root -ppadnet<filename.sql
  • 36. CHANGE MASTER TO master_host='master_ip_addresss',master_password='password',master_user='repuser', master_log_file='log file name',master_log_pos=pos; FLUSH PRIVILEGES; start slave; show slave statusG @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ DB3 mysql> insert into user(host,user,password,select_priv) values ('%','root',password('mysql'),'Y'); ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value Db2 mysql> insert into user(host,user,password,select_priv) values ('%','root',password('mysql'),'Y'); Query OK, 1 row affected, 3 warnings (0.00 sec) http://www.tecmint.com/how-to-setup-mysql-master-slave-replication-in-rhel-centos-fedora/