"MySQL" MySQL master-slave copy

Source: Internet
Author: User

MySQL master-slave replication configuration

Primary server: 192.168.0.100

From the server

192.168.0.101

Primary server Configuration

My.ini (Window under Linux is MY.CNF)

#开启二进制日志

Log-bin=mysql-bin

#给服务器起一个唯一的id

Server-id=1

#指定日志格式

Binlog-format=mixd

Authorization to 192.168.0.101 from the database server
Mysql> GRANT REPLICATION SLAVE on * * to ' user ' @ ' 192.168.0.101 ' identified by ' password ';

Querying the primary database state
Mysql> Show master status;

+------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+------------------+----------+--------------+------------------+
| mysql-bin.000008 | 998 | | |
+------------------+----------+--------------+------------------+

From server configuration

#配置从服务器
Log_bin=mysql_bin
server_id=2
Relay_log=mysql-relay-bin
Log_slave_updates=1
Read_only=1

Executing a synchronous SQL statement
Mysql> Change Master to
Master_host= ' 192.168.0.100 ',
master_user= ' user ',
master_password= ' Password ',
Master_log_file= ' mysql-bin.000008 ', #和上面的一致
master_log_pos=261;

Start slave synchronization process after correct execution
mysql> start slave;

Master-Slave synchronization check
Mysql> Show Slave Status\g

When MySQL master-slave replication occurs in show slave status\g when the value of slave_io_running or slave_sql_running is not yes, you need to stop the slave server first through stop slave, Then perform the above steps again to recover, but if you want to synchronize more data as possible, you can slave the value of the Master_log_pos node on the basis of the value of the previous synchronization failure, and then test repeatedly until the synchronization OK. Because the principle of MySQL master-slave replication is to read the master server from the server Binlog, and then update the database according to the Binlog Records

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.