Build a MYSQL master-slave replication structure and a mysql master-slave replication Structure

Source: Internet
Author: User

Build a MYSQL master-slave replication structure and a mysql master-slave replication Structure

1. Select two servers as the master and backup databases respectively.

2. log on to the server,

Yum install mysql;

Yum install mysql-server;

3. Start the server

Service mysqld start

4. log on to mysql as the root user and execute the following commands to add and authorize the replication user (both the master and slave nodes are in the 192.168.119. * network segment. Both sides are created to facilitate Master/Slave switchover)

Grant replication slave, replication client on *. * to repl @ '192. 192.% 'identified by '20160301 ';

5 Configure/etc/my. cnf

Server 1 (master)

Log_bin = mysql_bin
Server_id = 1

Second server (Backup)

Log_bin = mysql_bin
Server_id = 2
Read_only = 1

6. log on to the master (root) for execution.

Show master status \ G;

Display

File: mysql-bin.000001
Position: 106


Log on to the slave database (root) for execution

Test whether mysql-urepl-h192.168.119.128-p1234 can be connected to the master database. Do not check the firewall or/etc/my. cnf for access restrictions. modify the configuration.

Log on to the local database using mysql-uroot and run the following command:

CHANGE MASTER
MASTER_HOST = '1970. 168.119.128 ',
MASTER_USER = 'repl ',
MASTER_PASSWORD = '000000 ',
MASTER_LOG_FILE = 'mysql-bin.000001 ',
MASTER_LOG_POS = 106;

Start slave;

Show slave status \ G;

7. Create a table in the master database and view the table in the slave database.

The MySQL server is running with the -- read-only option so it cannot execute this statement

Because the slave database is configured as read_only









Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.