HA is a basic requirement to read and write the main database msql separated from the disaster backup copy
Prior to this master-slave replication we need the following conditions
- Master database and ensure consistent version of the database from mysql
- matser and closed the data from the database firewall ports open
Well, to open out to the brothers Oliver dry would be finished
First, we want the configuration information of the primary database
In the database system in the main database landlord win Examples
Find the mysql configuration file my.ini
Please copy the my.ini file before configuring a backup!
Please copy the my.ini file before configuring a backup!
Please copy the my.ini file before configuring a backup!
Configure the following parameters
(Ctrl + f fast operating parameters If there are changes, then you do not have this parameter you can add - -!)
# Here is the back of the note Data directory logging information is not the main database read from the database but the saved file name! Log -bin = " G: \ MySQL \ Data \ logbin " # main database here is read from the database Note data exception information back catalog but not save the file name ! log -error = " G: \ MySQL \ data \ LOGERR " # default service number 1 Server -id = 1 # you want to copy the data to fill in here database name binlog - do -db = Demo # not need to copy the database system library can fill in here binlog -ignore-db = MySQL # details see HTTPS: // www.cnblogs.com/langtianya/p/5504774.html here default binlog_format = STATEMENT
After configuration is complete restart the database
Right -> Restart
If that fails, please check your configuration is correct! Backup is very important !!!
Next we look at the state of the primary database
SHOW MASTER STATUS;
The following message indicates that the database configuration is complete!
Remember these two parameters will be used later
接下来要配置咱们的从数据库了 首先打开咱们的终端
进入 etc
cd /etc
进入咱们的数据配置文件
vim my.cnf
添加箭头中的两个配置
添加完成后保存退出
接下来重启数据库
systemclt restart mysql
等待一会重启成功后
一抹翠绿代表启动成功!
好了接下来 我们完成最后一步就能连接啦!
首先操作主数据库 创一个用户
GRANT REPLICATION SLAVE ON *.* TO '定义你用户名'@'从数据库ip' IDENTIFIED BY '123456'
执行成功后
我们要用这个用户连接到咱们的主数据库
在从数据库中
# 这里填写你的主数据库ip CHANGE MASTER TO MASTER_HOST='192.168.0.102', # 连接的用户名 MASTER_USER='haoran', # 用户名密码 MASTER_PASSWORD='123456', # 这两个参数 读取的日志名称 和切入点 MASTER_LOG_FILE='logbin.000002',MASTER_LOG_POS=750
最后一项数据的应该咱们配置 就是我们之前的查出来的这两个数据!
配置完成后 别着急
还有一步
在从数据库执行
START SLAVE;
当执行成功后 代表主从复制已经搭建好了
测试一下
在主数据建库建表插数据 数据库名必须是之前的binlog_do_db 配置项的名称
主数据库
从数据库