The construction of mysql master-slave database

 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 ip192.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、链接成功后验证是否主从同步

在主库上的test库上建立名为myTest的表
mysql> CREATE TABLE `myTest` (
`id` INT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 20 ) NOT NULL ,
`password` CHAR( 32 ) NOT NULL ,
`last_update` DATETIME NOT NULL ,
`number` FLOAT( 10 ) NOT NULL ,
`content` TEXT NOT NULL ,
PRIMARY KEY ( `id` ) 
) ENGINE = MYISAM ;
在从表中马上看到了效果,主从同步成功了;
为了更进一步验证在从库上输入show slave status/G;
mysql> show slave status/G;
Slave_IO_Running: Yes(网络正常);
Slave_SQL_Running: Yes(表结构正常)

 

进一步验证了以上过程的正确性。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326643804&siteId=291194637