Mysql5.5 master-slave replication Configuration

Source: Internet
Author: User

 

1. edit my. cnf in the master database:

[Mysqld]

Log-bin = NEW_NAME

Server-id = 1 # configure a unique ID number, ranging from 1 to 32.

# Set the name of the database for master-Slave replication or not, and set it on Slave.

Binlog-do-db = database name 1

Binlog-do-db = database name 2

Binlog-ignore-db = database name 1

Binlog-ignore-db = database name 2

Mysql> grant replication slave on *. * to slaveuser@192.168.1.101 identified by '2013 ';

Mysql> flush privileges;

Mysql> show master status;

+ ------------------ + ---------- + -------------- + ------------------ +

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+ ------------------ + ---------- + -------------- + ------------------ +

| Mysql-bin.000008 | 337 |

+ ------------------ + ---------- + -------------- + ------------------ +

Record the binary log file name and location

 

2. edit my. cnf from the database and change the server-id to a number different from that of the host.

If you only want to synchronize the specified database, you can add replicate-do-db = yourdatabase,

If you want to synchronize a few, just copy a few and change the database name.

[Mysqld]

Server-id = 2 # unique

# Set the name of the database for Master-slave replication or not, and set it on the Master.

Replicate-do-db = database name 1

Replicate-do-db = database name 2

Replicate-ignore-db = database name 1

Replicate-ignore-db = database name 2

 

Mysql> change master to master_host = '192. 168.1.100 ', master_user = 'slaveuser', master_password = '000000', master_log_file = 'mysql-bin.000008', master_log_pos = 192;

Mysql> start slave;

Mysql> show slave status \ G;

If:

Slave_IO_Running: Yes

Slave_ SQL _Running: Yes

If both of the preceding values are Yes, it means no problem. If you specify an individual database, you can also see

NOTE: If Slave_ SQL _Running: connecting occurs, first enter:

# Mysql-uslaveuser-h 192.168.1.100-p123456

Check whether you can log on to mysql. If the request is rejected, check whether the slave database authorization operation on the host is set correctly.

 

If the initial environment is not a master-slave architecture and data has been available for a period of time, you must first lock the Host: flush tables with read lock;

Package the data directory of the Host: # tar zcf/tmpdatabak. tgz/opt/data, copy the compressed package to the slave machine, decompress the package, and configure the master.

Then unlock: unlock tables;

 

Iloveyin

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.