MySQL master-slave replication Environment setup

Source: Internet
Author: User

MySQL Master

The first time I use a different version of MySQL will be out of sync problem, it is recommended to use the same version of MySQL from


    1. Main my.cnf file (192.168.1.64)

MYSQLD module Join

Log-bin=mysql-bin starting a binary file

Server-id=1 Server ID

Binlog-do-db = The library name that needs to be copied can be used, split

If the primary database contains data

First, the lock table operation, do not let the data write action, so doing to prevent from the original data from the database and the primary database is inconsistent with the original data.

Master enters MySQL

Mysql> flush tables with read lock;

mysqldump–uroot–p123456 TestDB >/home/testdb.sql

Scp-r/home/testdb.sql [Email protected]:/home

From entering MySQL

Create Database TestDB;

Mysql-u Root "Your database name" < "Your SQL file"

Unlock tables after the finish; Unlock table Actions

Enter MySQL new user and give from using #grant replication slave on * * to ' test ' @ ' 192.168.1.12 ' identified by ' 1234 '; ' Test ' @ ' 192.168.1.12 ' identified by ' 1234 ' with Grant Option;show master status;| File | Position | binlog_do_db | binlog_ignore_db |+------------------+----------+--------------+------------------+|      mysql-bin.000002 | 106 |                  TestDB | |+------------------+----------+--------------+------------------+


2. From my.cnf file (192.168.1.12)


MYSQLD module Join

Log-bin=mysql-bin starting a binary file

server-id=2 Server ID

Enter Mysqlchange master to master_host= ' 192.168.1.64 ', master_user= ' test ', master_password= ' 1234 ', master_log_file= ' Mysql-bin.000002 ', Master_log_pos=2852;start slave;show slave status\g
mysql>  show slave status\g*************************** 1. row **********                 slave_io_state: waiting for master to send event                   master_host: 192.168.1.64                    master_user: test                   Master_Port: 3306                 Connect_Retry: 60               Master_Log_File: mysql-bin.000002           read_master_log_pos: 2852                Relay_Log_File: mysqld-relay-bin.000002                 Relay_Log_Pos: 251         relay_master_log_file: mysql-bin.000002              Slave_IO_Running: Yes             Slave_sql_running: yes

Requires slave_io_running and SQL equals yes.

If one of the two has no Yes

Check database user rights and firewalls,

Log in to the main test mysql-h192.168.1.64-utest-p from the server

Checking the ServerIP

Mysql> Show variables like ' server_id ';

or slave stop; Slave start;

If it doesn't work, just load the same two versions of MySQL test.




MySQL master-slave replication Environment setup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.