Build a MYSQL master-slave replication structure and a mysql master-slave replication Structure
1. Select two servers as the master and backup databases respectively.
2. log on to the server,
Yum install mysql;
Yum install mysql-server;
3. Start the server
Service mysqld start
4. log on to mysql as the root user and execute the following commands to add and authorize the replication user (both the master and slave nodes are in the 192.168.119. * network segment. Both sides are created to facilitate Master/Slave switchover)
Grant replication slave, replication client on *. * to repl @ '192. 192.% 'identified by '20160301 ';
5 Configure/etc/my. cnf
Server 1 (master)
Log_bin = mysql_bin
Server_id = 1
Second server (Backup)
Log_bin = mysql_bin
Server_id = 2
Read_only = 1
6. log on to the master (root) for execution.
Show master status \ G;
Display
File: mysql-bin.000001
Position: 106
Log on to the slave database (root) for execution
Test whether mysql-urepl-h192.168.119.128-p1234 can be connected to the master database. Do not check the firewall or/etc/my. cnf for access restrictions. modify the configuration.
Log on to the local database using mysql-uroot and run the following command:
CHANGE MASTER
MASTER_HOST = '1970. 168.119.128 ',
MASTER_USER = 'repl ',
MASTER_PASSWORD = '000000 ',
MASTER_LOG_FILE = 'mysql-bin.000001 ',
MASTER_LOG_POS = 106;
Start slave;
Show slave status \ G;
7. Create a table in the master database and view the table in the slave database.
The MySQL server is running with the -- read-only option so it cannot execute this statement
Because the slave database is configured as read_only
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.