Implementation principle:
The master-slave synchronization of mysql is mainly realized through bin-log, which is controlled by the database server rather than the storage engine. The general idea is that the master server refreshes the disk from the log buffer and generates a bin-log file. The socket message is sent to the slave. After the slave is executed (it may fail or succeed), it reports a message to the master, and the master determines whether to commit or rollback according to the situation.
Configure master-slave replication:
configure my.cnf.
1), master:
grant replication slave on *.* to jk identified by '123456';
or: GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by ' q123456';
2), Slave:
the pointing of the slave:
change master to
->master_host='223.202.75.63',
->master_port=3306,
->master_user='jk',
->master_password='123456';
3), Start slave:
start slave;
show slave status\G;
show master status\G;
master configuration:
[client]
port=3306
default-character-set=utf8
[mysqld]
port=3306
character_set_server=utf8
#character_set_server=utf8 must be written like this;
basedir=C: \Program Files\MySQL\mysql-5.6.16-win32 #Decompression
directory
datadir=C:\Program Files\MySQL\mysql-5.6.16-win32\data #The
data directory in the decompression directory must be the data directory
#sql_mode=NO_ENGINE_SUBSTITUTION ,STRICT_TRANS_TABLES This has a problem. After creating a new user login, an error
sql_mode=NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION #Master
server configuration #Open
binary log
log-bin=master-bin #Use
the index file of the binary log
log-bin-index=master. bin.index
#Add a unique number for the
server server-id=1
slave configuration:
[client]
port=3306
default-character-set=utf8
[mysqld]
port=3306
character_set_server=utf8
#character_set_server=utf8 must be written like this;
basedir=C: \Program Files\MySQL\mysql-5.6.16-win32 #Decompression
directory
datadir=C:\Program Files\MySQL\mysql-5.6.16-win32\data #The
data directory in the decompression directory must be the data directory
#sql_mode=NO_ENGINE_SUBSTITUTION ,STRICT_TRANS_TABLES There is a problem with this. After creating a new user login, an error
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
server-id=2
relay-log=slave-relay-log-bin
relay-log-index=slave-relay-log-bin.index
Understand the principle and configuration of mysql_mysql master-slave
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326227716&siteId=291194637
Ranking