MySQL database replication master-slave synchronization

Primary database: 192.168.1.31/24
Vim /etc/my.cnf
[mysqld]
DATADIR = / usr / local / MySQL / Data /
Socket = / tmp / mysql.sock

and Slave #MASTER
# enable binary logging
log-bin = MySQL-bin-Master
# native database ID label
Server-the above mentioned id = 1
# can be copied from the server database, the database name binaries need to be synchronized
binlog-do-db = test
# may not be copied from the server database
binlog-ignore-db = mysql

[mysqld_safe]
log-error=/usr/local/mysql/log/err.log
pid-file=/usr/local/mysql/data/mysql.pid

Restart /etc/init.d/mysqld restart

Log database authorized a sub-account, so that the database can be synchronized to the master binary information log
mysql> Grant Slave Replication ON . To [email protected] IDENTIFIED by "123456";
mysql> flush privileges; # refresh permission
mysql > select * from mysql.user where user = 'slave' \ G; # can be omitted, which is authorized to view the number of rights which

From the database: 192.168.1.32/24
Vim /etc/my.cnf
[mysqld]
DATADIR = / usr / local / MySQL / Data /
Socket = / tmp / mysql.sock

and Slave #MASTER
# line is provided only on the line ID and save
server-id = 2

[mysqld_safe]
log-error=/usr/local/mysql/log/err.log
pid-file=/usr/local/mysql/data/mysql.pid

Restart /etc/init.d/mysqld restart

Testing can not log on the primary database 192.168.1.31/24 can be omitted
log OK mysql -uslave -p123456 -h192.168.1.31 results

Log from the library, stop the Slave
MySQL> STOP Slave;

授权主库
mysql>change master to master_host='192.168.1.31',master_port=3306,master_user='slave',master_password='123456',master_log_file='mysql-bin-master.000001',master_log_pos=602;

开启slave
mysql> start slave

mysql> show slave status \ G # View from the main success has nothing to do
see these two threads from main to prove so successful!
Slave_IO_Running: YES
Slave_SQL_Running: YES

Guess you like

Origin blog.51cto.com/kangxi/2422931