0% found this document useful (0 votes)
59 views2 pages

Mysql Replication Master To Slave

This document provides steps to configure MySQL master-slave replication between two servers. It describes how to set the master server to log database changes, grant replication privileges, and backup the database. It also explains how to prepare the slave server by importing the backup, configuring replication settings, and starting the replication process to sync the slave database with the master.

Uploaded by

Daniel D. Torres
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views2 pages

Mysql Replication Master To Slave

This document provides steps to configure MySQL master-slave replication between two servers. It describes how to set the master server to log database changes, grant replication privileges, and backup the database. It also explains how to prepare the slave server by importing the backup, configuring replication settings, and starting the replication process to sync the slave database with the master.

Uploaded by

Daniel D. Torres
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Replicating Master to Slave (MySQL)

Install MySQL yum install mysql-server mysql php-mysql Set the MySQL service to start on boot -chkconfig --levels 235 mysqld on Start the MySQL service -service mysqld start Log into MySQL -mysql -u root Set the root user password for all local domains -SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new-password'); -SET PASSWORD FOR 'root'@'localhost.localdomain' = PASSWORD('new-password'); -SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('new-password'); Drop the Any user -DROP USER ''@'localhost'; -DROP USER ''@'localhost.localdomain'; Exit MySQL -exit

Configure Master Host


$ vim /etc/my.cnf Add this line under [mysqld] log-bin = /var/log/mysql/mysql-bin.log binlog-do-db=yourDB server-id=1 restart mysql service mysqld restart Log in to mysql mysql -u root -p mysql>GRANT REPLICATION SLAVE ON yourDB TO 'SLAVE_NAME'@'IP ADD/USER' IDENTIFIED BY 'YOUR_PASSWORD'; mysql> FLUSH PRIVILEGES; mysql> FLUSH TABLES WITH READ LOCK; mysql> SHOW MASTER STATUS; +-------------------------+------------+---------------------+----------------------------+

# database replicate # serve as a unique id # Refresh the configuration my.cnf

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB +-------------------------+------------+---------------------+----------------------------+ | mysql-bin.000001 | 16310 | testdb | | +-------------------------+------------+---------------------+----------------------------+ 1 row in set (0.00 sec) mysql> UNLOCK TABLES; mysql>\q mysqldump u root p --opt yourDB > yourDB.sql

Configure Slave Host


scp root@IP:/location /home mysql u root p mysql> create database yourDB; mysql> \q mysql -u root -p yourDB < /home/yourDB.sql $ vim /etc/my.cnf add this under the [mysqld] /etc/my.cnf server-id =2 master-host = MASTER_IP_ADDRESS master-user = SLAVE_NAME master-password = YOUR_PASSWORD master-connect-retry = 60 replicate-do-db = yourDB restart mysql service mysqld restart log-in to mysql mysql u root p mysql> SLAVE STOP; mysql> CHANGE MASTER TO MASTER_HOST='MASTER_IP_ADDRESS', MASTER_USER='SLAVE_NAME', MASTER_PASSWORD='YOUR_PASSWORD', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=16310; mysql> SLAVE START; mysql>\q note: MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=16310 must the same on the status of the master. Test Replication Insert Something in the master database.

You might also like