CentOS mysql configuration master-slave replication

surroundings:

centos 7.0
mysql5.6 (yum package yum localinstall mysql-yum)

1、 The master and slave servers respectively do the following operations:

2、 Modify the master server master:

# vi /etc/my.cnf
 [ mysqld]
 log-bin=mysql-bin   //[have to]Enable binary log
 server-id=232//[have to]The unique ID of the server, the default is 1, usually the last segment of the IP

3、 Modify slave server:

# vi /etc/my.cnf
 [ mysqld]
 log-bin=mysql-bin   //[Not required]Enable binary log
 server-id=222//[have to]The unique ID of the server, the default is 1, usually the last segment of the IP

4、 Restart mysql of two servers

service mysqld restart

//If the startup is not successful,View log, usually my.cnf configuration problem
cat /var/log/mysqld.log

5、 Create an account on the master server and authorize the slave:

GRANT REPLICATION SLAVE ON *.* to 'hs'@'%' identified by 'a123.+-';//Generally, the root account is not required,@;%;Means that all clients can connect, as long as the account and password are correct, the specific client IP can be used instead, such as 192.168.0.1. Strengthen safety.

6、 Log in to the mysql of the master server and query the status of the master###

 mysql>show master status;+------------------+----------+--------------+------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000003|712|||+------------------+----------+--------------+------------------+1 row inset(0.00 sec)//Note: Do not operate the main server MYSQL after performing this step to prevent the main server status value from changing

7、 Configure the slave server Slave:

mysql>change master to master_host='192.168.0.232',master_user='hs',master_password='a123.+-',master_log_file='mysql-bin.000003',master_log_pos=712;   
Mysql>start slave;//Start copy function from server

8、 Check the status of the replication function from the server:

 mysql> show slave status\G
 Slave_IO_State: Waiting for master to send event
 Master_Host:192.168.0.232//Primary server address
 Master_User: hs   //Authorized account name, try to avoid using root
 Master_Port:3306//Database port, some versions do not have this line
 Connect_Retry:60
 Master_Log_File: mysql-bin.000003
 Read_Master_Log_Pos:600//#Synchronously read the location of the binary log, greater than or equal to Exec_Master_Log_Pos
 Relay_Log_File: ddte-relay-bin.000003
 Relay_Log_Pos:251
 Relay_Master_Log_File: mysql-bin.000004
 Slave_IO_Running: Yes    //This status must be YES
 Slave_SQL_Running: Yes     //This status must be YES......//Note: Slave_IO and Slave_The SQL process must run normally, that is, the YES state, otherwise it is an error state(Such as: one of the NO is an error)。

The above operation process, the master-slave server configuration is completed. The following is to build a library to insert data to test

Recommended Posts

CentOS mysql configuration master-slave replication
Centos MySQL8 configuration
Centos mysql installation and configuration
Centos7 mysql database installation and configuration
CentOS7 install MySQL
CentOS7.0 network configuration
CentOS 7.0 network configuration
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
CentOS install mysql
CentOS7 install mysql
CentOS 7 install MySQL 5.6
CentOS8 install MySQL8.0
CentOS7 install mysql8
CentOS7 install MySQL8
centos 7.5 install mysql5.7.17
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
Xfs configuration on centos7
CentOS6.5 offline install MySQL5.6.26
Install MySQL5.7 in centos7
Install mysql5.7 under CentOS7
Centos kernel compilation configuration
CentOS 7.2 Yum install MySQL 5.6
Centos7 install Mysql8 tutorial
Centos manually install mysql8
Install mysql under Centos 7
CentOS7 reset MySQL8.0 password
Centos7 install Mysql database
Install mysql5.1 under CentOS6.5
CentOS7 enables MySQL8 master-slave backup, daily scheduled full backup (recommended)
Environment configuration of JDK, mysql and tomcat under Centos7
Install mysql online on centos
centos install mysql through yum
Centos7.4 deployment configuration Elasticsearch5.6 cluster
Centos7 installation and configuration prometheus
Build MariaDB replication on CentOS
Install MySQL 8.0.16 on Linux Centos
CentOS 6.x installation mysql5.7 record
CentOS installation and configuration cmake
Install MySQL under Linux (CentOS 7)
CentOS 7 user account configuration original
Centos6 install mysql 5.7.x series
Implementation of CentOS8.0 Network Configuration
CentOS 7 Redis 5.0.8 sentinel mode configuration
CentOS8 network card configuration file
CentOS8 install MySQL8 (pro test)
How to install MySQL on CentOS 8
CentOS7 yum install and start mysql
Centos7 installation and configuration of Jenkins
CentOS Yum compile and install MySQL 5.6
CentOS 8 install Git and basic configuration
CentOS 7 install Nginx, PHP, MySQL packages
Centos7 hadoop cluster installation and configuration
CentOS configuration git server in VirtualBox
Install MySql with Docker in CentOS7
Performance comparison of MySQL centos 6 vs 7
CentOS7.2 and Nginx configuration virtual host
Detailed examples of Centos6 network configuration
CentOS7 yum install and start mysql
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos yum install mysql5.6 or above
Java-JDK installation and configuration under CentOS