Deploy MySQL master-slave on CentOS7

2 Locate the directory my.cnf file resides:
MySQL –help | grep my.cnf
general my.cnf are located in /etc/directory;

3 with vim open MySQL configuration file my.cnf:
vim /etc/my.cnf

4 Locate the [mysqld] and subsequently add the following configuration:
# uniquely identifies this MySQL server, the default value is 1, the general IP terminal belongs value
server-id=1
# binary log file name, MySQL master server must enable this configuration
log-bin=master-bin-log
# master server in the MySQL database name involved in master-slave replication; if there are multiple databases, this parameter can have multiple, one per line, divisions corresponding to different database
binlog-do-db=db_master_slave
# master the MySQL server binary log file name in the index of
log-bin-index=master-bin-log.index

Also open from 5 in the MySQL server using vim my.cnf file, locate the [mysqld], and add the following configuration at the rear:
# uniquely identifies this MySQL server, the default value is 1, the general IP terminal belongs value
server-id=2
# log index file name from the MySQL server the above mentioned id
relay-log-index=slave-relay-log.index
# log file name from the MySQL server
relay-log=slave-relay-log

6, respectively, to create a database db_master_slave on MySQL master and slave servers:
the Create Database db_master_slave;
create database db_master_slave;

7 Create user user_master on MySQL master server, and set a password Password_Master_123456: the Create the User ‘user_master’ @ ‘%’ IDENTIFIED by ‘Password_Master_123456’;
create user ‘user_master’@’%’ identified by ‘Password_Master_123456’;

8 on MySQL master server for users user_master Empowering all rights db_master_slave database:
grant all on db_master_slave.* to ‘user_master’@’%’;

9 On the MySQL master server for the local user access privileges assigned user_master:
grant all privileges on db_master_slave.* to ‘user_master’@’localhost’ identified by ‘Password_Master_123456’;

10 Authorized MySQL slave servers on a MySQL master server can access the host server by user_master User:
grant replication slave on *.* to ‘user_master’@’%’ identified by ‘Password_Master_123456′ with grant option;

11 On the MySQL master and slave servers are restarted MySQL service:
closed MySQL service:
service mysqld stop
open MySQL service:
service mysqld start
restart the MySQL service:
service mysql restart

12 On the MySQL master and slave servers are entered into the database db_master_slave:
use db_master_slave;
create table t_user(id int(3), name varchar(128));

13 See MySQL master server status:
show master status;
the value of its properties and master_log_pos master_log_file property and records;

14 executed on a MySQL slave service as follows:
Change to Master MASTER_HOST =’192.168.1.10′, // the MySQL Master server the IP
MASTER_PORT=3306,
MASTER_USER=’user_master’,
master_password=’Password_Master_123456′,
MASTER_LOG_FILE=’Master-bin-log.000004 ‘, // MySQL master server master_log_file value
master_log_pos=654; // value of MySQL master server master_log_pos

15 db_master_slave library MySQL master server to add data to the user name T_USER:
mysql> insert into t_user(id, name) values(1, ‘idea1’);
mysql> select * from t_user;

16 db_master_slave library MySQL slave server to add data to the user name T_USER:
mysql> insert into t_user(id, name) values(1, ‘idea1’);
mysql> select * from t_user;

17 MySQL slave servers how to discover:
slave_IO_running = NO
then execute the following command:
mysql> stop slave;
mysql> start slave;

18 See MySQL runtime server_id values:
show variables like ‘server_id’;

Leave a comment

Your email address will not be published. Required fields are marked *

Blue Captcha Image
Refresh

*

Protected by WP Anti Spam

Hit Counter provided by dental implants orange county