MySQL Master-slave configuration

Source: Internet
Author: User

MySQL 5.6 X64 & CentOS 7

Main Library: 192.168.1.1

From library: 192.168.1.2

1. Main Library Configuration

Vi/etc/my.conf

Set the following parameters under [mysqld]:

Server-id=1 #主库标识
Log_bin=mysql-bin #开启mysql二进制日志
#binlog-do-db=mydb #要复制的数据库
#binlog-ignore-db=mysql #忽略的数据库

Save exit, restart Service, view host binary log status

Service MySQL Restart
Mysql-u root-p
Show master status; #查看主服务器状态
+------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 616 | Osyunweidb | MySQL |
+------------------+----------+--------------+------------------+
1 row in Set (0.00 sec)

To open an account from the server, user name sync limit IP, only give replication permissions

Grant Replication Slave on * * to ' sync ' @ ' 192.168.1.2 ' identified by ' 123456 ' with GRANT option;
Flush privileges;

2, from the library configuration

Vi/etc/my.conf

Set the following parameters under [mysqld]:

server-id=2 #从库标识位
Log-bin=mysql-bin
#binlog-do-db=mydb #要复制的数据库
#binlog-ignore-db=mysql #忽略的数据库

Save exit, restart Service

Service MySQL Restart
Mysql-u root-p
Slave stop; # Stop from library feature
Change Master to master_host= ' 192.168.1.1 ', master_user= ' sync ', master_password= ' 123456 ', master_log_file= ' Mysql-bin.000001 ', master_log_pos=616;

#设置同步参数 Host user name password binary file location
Slave start; # Start from library feature
Show slave status \g #查看从库状态
Normal configuration, you can start synchronizing from the library by reading the binary log of the main library.

Slave_io_running:yes
Slave_sql_running:yes
Slave_io_running refers to the process state that reads the main library binary log slave_sql_running is the state of the binary log executed from the library

Both of these are yes, which means that the binary operations log from the library reads the main library and executes synchronously in the native, which naturally realizes the function of master-slave replication.

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.