MySQL Master-slave configuration

Source: Internet
Author: User

System environment: centos6.7 MySQL


Master ip:192.168.16.110

Slave ip:192.168.16.12


Primary server

1.vim/etc/my.cnf

Append the following content:

[Mysqld]

Log-bin=test-log #启用二进制文件

server-id=110 #服务器编号


2. Restart the mysqld of the primary service and turn off the firewall

Server mysqld Restart

Server Iptables Stop


3. Add users who can connect from the server

Mysql-uroot-p

Create user ' slave ' @ ' 192.168.16.12 ' identified by ' slave ';

Grant Replication Slave on * * to ' slave ' @ ' 192.168.16.12 ';

Exit


4. Get the primary server binary log information

Mysql-uroot-p

Flush tables with read lock;

Show master status;

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

| File | Position | binlog_do_db | binlog_ignore_db |

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

|  mysql-bin.000009 |              3550020 |                  | |

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

Unlock tables;


From the configuration:

    1. Vim/etc/my.cnf

Append the following content:

[Mysqld]

Server-id=12 #服务器编号


2. Restart the mysqld of the primary service and turn off the firewall

Server mysqld Restart

Server Iptables Stop


3. Connecting the master server configuration

Mysql-u root-p

Change Master to master_host= ' 192.168.16.110 ',

Master_user= ' slave ',

master_password= ' slave ',

Master_log_file= ' mysql-bin.000009 ',

master_log_pos=3550020;


Start slave;

Show Slave Status\g



Data Synchronization Verification:

Create Database test2;

User Test2

CREATE TABLE T_table (

Name Char (20),

Age int,

Note varchar (50));


INSERT INTO t_table values

(' Rocky ', ' A ', ' Shanghai ');


Exit


MySQL Master-slave configuration

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.