MySQL master-slave replication configuration

Source: Internet
Author: User
Tags mixed unique id

Idea: To create a 2 log on the main service, each generation of statements or disk changes are written into the log, we can set up an account through the master server,

Modify the next my.cnf configuration file to let the server establish Relaylog, this time the master server creates a slave account, on the slave server

All over the statement to connect to the master server, turn on the replication function to achieve master-slave replication.

/USR/LIBEXEC/MYSQLD--skip-grant-tables detect password permission cancellation (Close MySQL entry requires account)

MySQL two servers create a master-slave replication configuration process:
I have two linux,ip for 199,200 under the virtual machine
1:200 doing from the server
2:199 doing the primary server
3: Ensure the master-slave 3306 Port Interoperability

4: Configure the primary server to open Binlog

         Edit MY.CNF
        # Give the server a unique ID
        server-id=199
         #binary log to open binary log
        log-bin=mysql-bin
         #statement Row Mixed
          #指定日志格式
        binlog-format=mixed/row/statement
         Description: The primary server log format has statement,row,mixed3, where mixed refers to the first two hybrid
         row: Generally, it's better to have a row with row
         Statement: When a statement is made for each row of the database, many rows that are reflected on the disk have changed, which is appropriate for the statement format
         A mixed format supported by the Mixed:2 form

Restart MySQL
Show Master status;//See if Master is already acting as the primary server

5: Configure Slave server


#relay log from the server to relay logs

Relay-log=mysql-relay
Server ID
server-id=200
#指定只读
Read-only=1
Restarting the server

6: Create a Slave account on the main service

Grant Repliaction slave,replication Client on *. *
To ' repl ' @ ' 192.168.%.% ' identified by ' repl ';
Refresh MySQL Permissions
Flush privileges;

7: Specify the server to replicate from the server through the statement (note: Can one master many from, can not one from multi-master)
->change Master to
->master_host= ' 192.168.0.199 ',
->master_user= ' Repl ',
->master_password= ' Repl ',
->master_log_file= ' mysql-bin.000003 ',
->master_log_pos=278;
?
8: Start replication from the server
->start slave;
->show slave status; View the state of slave

9: You can manipulate the database on the primary server to see if replication succeeded from the server database

Common statements
Show master status; View the state of master, especially the current log and location
show slave status; View the state of slave
reset slave; reset slave status
start slave; Activate slave status (start listening for master changes)
stop slave; pause slave status





MySQL master-slave replication 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.