MySQL master-slave database construction
Time of writing this article: 2012/8/27
Environment:
( The following is the environment I used for this build )
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
- Master Database A :
系统:window7; MYSQL 5.6.24 ;ip:192.168.1.111<!--[if !supportLineBreakNewLine]--><!--[endif]-->
- from database B
system: window 7 ; MYSQL 5.6.24 ; ip : 192.168.1.120
Steps: 1. Configure the mysql file my.ini on the main server A
/mysql/my.ini
service_id=1 #Main server ID
log-bin=mysql-bin #If there is no binary log , you can create a new one in the root directory
binlog-do-db=yf_vehicle #The name of the database to be synchronized on the master server
binlog-ignore-db=test #Database name that does not need to be synchronized
binlog-ignore-db=mysq l# The name of the database that does not need to be synchronized (multiple can be separated by commas)
2. Create an admin account with a password of 123456 , in order to monitor the link from the database B.
3. Start the mysql service from the start
4. Configure the mysql file my.ini from server B
/mysql/my.ini
service_id =2
replicate-to-db=yf_vehicle
binlog-ignore-db=test
binlog-ignore-db=mysql
5. Authorization
1 ) The master server authorizes the slave server
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.120' IDENTIFIED BY '123456' WITH GRANT OPTION;
6. Main server display configuration;
show master status;
+------------------+----------+--------------+--------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+--------------------------+
|mysql-bin.000007| 3708| yf_vehicle | mysql |+------------------+----------+--------------+--------------------------+<!--[if !supportLineBreakNewLine]--><!--[endif]-->
7. Configure monitoring from server B
change master to master_host=’192.168.1.111,master_user=’admin’,master_password=’123456’,master_log_file=’mysql-bin.000007′,master_log_pos=3708;
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
8、从服务器从启 slave
stop slave;
start slave;
9、查看运行状态;
show slave status;
请查看附件1
这里特别说明一下 : 如果slave_IO_Running:no 或者SLave_io_state是空的情况 :两种情况
1)、你的mysql数据库是copy的所以你两个数据库的UUID是一样的。请改动一个,位置是/mysql/data/auto.cnf
这个文件里的service-uuid。查看是否一样。
2)、你配置的主从服务器中的service_id一样导致从服务器无法连接主服务器。
10、链接成功后验证是否主从同步