MySQL-(Master-Slave)配置
1、两台机器,安装好版本一致的MySQL
192.168.29.128 (master) MySQL-5.6.21
192.168.29.129 (slave) MySQL-5.6.21
2、配置master
配置binary log和server ID
[root@Luxh-01 ~]# vi /etc/my.cnf
配置如下:
[mysqld]
log-bin=mysql-bin
server-id=1
重启MySQL
3、配置slave
[mysqld]
server-id=2
4、在master上创建用于复制的账号
mysql> create user 'repl'@'%' identified by '';
Query OK, 0 rows affected (0.13 sec) mysql> grant replication slave on *.* to 'repl'@'%' ;
Query OK, 0 rows affected (0.02 sec)
5、在master上查看 binary log文件名和 position
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
6、配置slave
mysql> change master to master_host='192.168.29.128',master_user='repl',master_password='',master_port=3306,master_log_file='mysql-bin.000003',master_log_pos=120,master_connect_retry=10;
Query OK, 0 rows affected, 2 warnings (0.30 sec)
使用上面创建的用于复制的账号,master_log_file使用master上查询出来的文件名,master_log_pos也必须使用master上查询出来的position
7、在slave上启动复制功能
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
8、查看slave的状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.29.128
Master_User: repl
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 120
Relay_Log_File: Luxh-02-relay-bin.000002
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 120
Relay_Log_Space: 458
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 9567210c-684f-11e4-b062-000c29398b4c
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
9、配置完毕。测试一下效果。
1)在master上执行以下语句
mysql> create database web_db;
Query OK, 1 row affected (0.04 sec) mysql> use web_db;
Database changed
mysql> create table t_user(id int primary key auto_increment,username varchar(32));
Query OK, 0 rows affected (0.13 sec) mysql> insert into t_user(username) values('lihuai');
Query OK, 1 row affected (0.05 sec) mysql> select * from t_user;
+----+----------+
| id | username |
+----+----------+
| 1 | lihuai |
+----+----------+
1 row in set (0.00 sec)
2)在slave上查看,看是否已成功复制
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| web_db |
+--------------------+
5 rows in set (0.05 sec) mysql> use web_db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+------------------+
| Tables_in_web_db |
+------------------+
| t_user |
+------------------+
1 row in set (0.00 sec) mysql> select * from t_user;
+----+----------+
| id | username |
+----+----------+
| 1 | lihuai |
+----+----------+
1 row in set (0.00 sec)
10、以上配置是针对全新安装的MySQL服务器做主从复制,还可以针对已有数据的数据库、或者已有的主从结构上再添加slave
具体配置,可以参考官网文档,非常详细。
http://dev.mysql.com/doc/refman/5.6/en/replication-howto.html
MySQL-(Master-Slave)配置的更多相关文章
- Windows下搭建MySQL Master Slave[转]
Windows下搭建MySQL Master Slave 一.背景 服务器上放了很多MySQL数据库,为了安全,现在需要做Master/Slave方案,因为操作系统是Window的,所以没有办法使用k ...
- Windows下搭建MySQL Master Slave
一.背景 服务器上放了很多MySQL数据库,为了安全,现在需要做Master/Slave方案,因为操作系统是Window的,所以没有办法使用keepalived这个HA工具,但是我们可以接受人工进行切 ...
- MySQL master/slave 模式
1 .复制 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的 数据复制到其它主机(slaves)上,并重 ...
- mysql (master/slave)复制原理及配置
1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重 ...
- MySQL的Master/Slave群集安装和配置
本文介绍MySQL的Master/Slave群集安装和配置,版本号安装最新的稳定版GA 5.6.19. 为了支持有限HA.我们用Master/Slave读写简单孤立的集群.有限HA这是当Master不 ...
- mysql 主从配置(master/slave)
1. 在每台服务器上创建复制账号(也可以只在master上创建用户,这里配置两个是为了方便以后切换) 备库运行的I/O县城需要建立一个到主库的TCP/IP连接,所以必须在主库创建一个用户,并赋予合适 ...
- 在阿里云Centos7.6上面配置Mysql主从数据库(master/slave),实现读写分离
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_85 在之前的一篇文章中,阐述了如何在高并发高负载的场景下使用nginx做后台服务的负载均衡:在阿里云Centos上配置nginx+ ...
- mysql主从复制 master和slave配置的参数大全
master所有参数1 log-bin=mysql-bin 1.控制master的是否开启binlog记录功能: 2.二进制文件最好放在单独的目录下,这不但方便优化.更方便维护. 3.重新命名二进制日 ...
- mysql5.7主从(Master/Slave)同步配置
环境: mysql版本都是5.7(以前的版本配置可能不一样) 主(Master) windows:192.168.0.68 从(Slave) centos7:192.168.0.4 基本环境配置: 要 ...
- MySQL5.6 数据库主从(Master/Slave)同步安装与配置详解
.安装环境 .基本环境配置 .Master的配置 .Slave的配置 .添加需要同步的从库Slave .真正的测试 安装环境 1 操作系统 :CentOS 6.5 2 数据库版本:MySQL 5.6. ...
随机推荐
- PR和VV的分类与区别
Adobe Premiere是一款常用的视频编辑软件,由Adobe公司推出.现在常用的有CS4.CS5.CS6.CC.CC 2014及CC 2015版本.是一款编辑画面质量比较好的软件,有较好的兼容性 ...
- uboot make xxx_config与make的过程分析
一直很想捋清楚make xxx_config,make 的执行过程. 在uboot的makefile中有这样的话: %_config::unconfig @$(MKCONFIG) -A $(@:_co ...
- python leetcode 日记 --Contains Duplicate II --219
题目: Given an array of integers and an integer k, find out whether there are two distinct indices i a ...
- git常用命令有用
http://www.cnblogs.com/cspku/articles/Git_cmds.html
- 进监狱全攻略之 Mifare1 Card 破解
补充新闻:程序员黑餐馆系统 给自己饭卡里充钱 ,技术是双刃剑,小心,小心! 前言 从M1卡的验证漏洞被发现到现今,破解设备层出不穷,所以快速傻瓜式一键破解不是本文的重点,年轻司机将从本文中获得如下技能 ...
- 多线程 or 多进程?[转]
在Unix上编程采用多线程还是多进程的争执由来已久,这种争执最常见到在C/S通讯中服务端并发技术的选型上,比如WEB服务器技术中,Apache是 采用多进程的(perfork模式,每客户连接对应一个进 ...
- PHP操作Excel – PHPExcel 基本用法详解
导出excel属性设置//Include classrequire_once('Classes/PHPExcel.php');require_once('Classes/PHPExcel/Writer ...
- 怎样禁用或启用"最近使用的项目"
1.右击“任务栏”——属性——‘开始’菜单——自定义——高级——去掉“列出我最近打开的文档”的勾选——确定.2.通过“组策略”来修改开始——运行——gpedit.msc——用户配置——管理模板——任务 ...
- js数组常用方法汇总
判断某个对象是否是数组: instanceof.Array.isArray() 对于一个网页或者一个全局作用域可以使用instanceof操作符. if(value instanceof Array) ...
- GT 940M 到底怎么样! 768的可以 1080的不要用了
而对于目前的市场来看,NVIDIA独显无疑是占据了产品端的绝对主力,9系列独显也已经全面上市,但除了大家熟悉的GTX级之外,入门级的更新也同样对入门级玩家有着至关重要的意义,其中最具代表性的莫过于今天 ...