MySQL-5.7.20主从复制测试[20180110]
主库
[root@t-xi-sonar01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.59 t-xi-sonar01
192.168.1.51 t-xi-orc01
从库
[root@t-xi-orc01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.51 t-xi-orc01
192.168.1.59 t-xi-sonar01
[root@t-xi-sonar01 ~]# service mysqld stop
Stopping mysqld: [ OK ]
[root@t-xi-sonar01 ~]# vim /etc/my.cnf
#Server ID,一般设置成IP地址的最后一位,如下测试就按后两位
server_id=
#开启log bin,名字最好有意义用来区分
log-bin=dev-bin
#需要进行复制的数据库,可以指定数据库
#binlog-do-db=DB_master
#不需要备份的数据库,可以设置多个数据库,一般不会同步mysql这个库
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
#为每个session 分配的内存,在事务过程中用来存储二进制日志的缓存
binlog_cache_size=1m
#二进制日志自动删除/过期的天数。默认值为0,表示不自动删除。
expire_logs_days=
# 跳过主从复制中遇到的所有错误或指定类型的错误,避免slave端复制中断。
# 如:1062错误是指一些主键重复,1032错误是因为主从数据库数据不一致
slave_skip_errors=
[root@t-xi-sonar01 ~]# service mysqld start
Starting mysqld: [ OK ]
[root@t-xi-sonar01 ~]# mysql 5.7.20登陆报错解决
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -u root
update user set authentication_string=PASSWORD("****") where User='root';
flush privileges; 主库创建同步账户
service mysqld start
mysql> mysql -u root -p
mysql> CREATE USER 'replication'@'192.168.1.51' IDENTIFIED BY 'slave';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.1.51';
mysql> flush privileges; 主库锁定后备份将资料同步到从库
mysql>use sonar
mysql>FLUSH TABLES WITH READ LOCK;
mysqldump -u root -p --databases sonar > sonar.sql
scp sonar.sql @192.168.1.51:/root
mysql> unlock tables;
[master-server]
mysql> show master status ;
+----------------+----------+--------------+---------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------+----------+--------------+---------------------------------------------+-------------------+
| dev-bin. | | | mysql,information_schema,performance_schema | |
+----------------+----------+--------------+---------------------------------------------+-------------------+
service mysqld stop
vim /etc/my.cnf
#add slave-server
server_id=
#binlog-ignore-db=mydql
#binlog-ignore-db=information_schema
#binlog-ignore-db=performance_schema
#log-bin=dev-slave-bin
binlog_cache_size=1M
binlog_format=mixed
expire_logs_days=
slave_skip_errors=
relay_log=dev-relay-bin
#log_slave_updates=
read_only= service mysqld start
将主库备份导入从库
mysql>source /root/sonar.sql
添加链接到主库同步复制的账户
mysql>CHANGE MASTER TO MASTER_HOST='192.168.1.59', MASTER_USER='replication', MASTER_PASSWORD='slave', MASTER_LOG_FILE='dev-bin.000001', MASTER_LOG_POS=; MASTER_LOG_FILE:指定log bin日志文件名称
MASTER_LOG_POS :指定同步复制log分区号,可以从0开始。 查看slave状态
show slave status \G Slave_IO_State #从站的当前状态
Slave_IO_Running: Yes #读取主程序二进制日志的I/O线程是否正在运行
Slave_SQL_Running: Yes #执行读取主服务器中二进制日志事件的SQL线程是否正在运行。与I/O线程一样
Seconds_Behind_Master #是否为0,0就是已经同步了
启动slave
start slave;
mysql> show slave status \G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.59
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: dev-bin.
Read_Master_Log_Pos:
Relay_Log_File: dev-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: dev-bin.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
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:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: d6901902-ea28-11e7-b859-000c29255261
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)
创建table和database测试 在sonar下建立测试表
mysql> use sonar;
mysql> create table slave_t(
-> id int() not null, name varchar()
-> )
-> ;
Query OK, rows affected (1.57 sec) mysql> insert into slave_t values(,'name01');
Query OK, row affected (0.33 sec) 创建slave_db测试数据库
mysql> use mysql
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> create database slave_db;
Query OK, row affected (0.17 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| slave_db |
| sonar |
| sys |
+--------------------+
rows in set (0.00 sec) mysql> use sonar;
Database changed
mysql> select * from slave_t;
+----+--------+
| id | name |
+----+--------+
| | name01 |
+----+--------+
row in set (0.00 sec)
主库上的table和database已同步复制过来
查看主库master状态
mysql> show master status;
+----------------+----------+--------------+---------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------+----------+--------------+---------------------------------------------+-------------------+
| dev-bin. | | | mysql,information_schema,performance_schema | |
+----------------+----------+--------------+---------------------------------------------+-------------------+
row in set (0.00 sec) 查看从库主机列表
mysql> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID |
+-----------+------+------+-----------+--------------------------------------+
| | | | | 86fff1d0-f62d-11e7-834d-000c29477dac |
+-----------+------+------+-----------+--------------------------------------+
row in set (0.00 sec) 查看bin log文件列表
mysql> show binary logs;
+----------------+-----------+
| Log_name | File_size |
+----------------+-----------+
| dev-bin. | |
| dev-bin. | |
| dev-bin. | |
| dev-bin. | |
+----------------+-----------+
rows in set (0.00 sec) 查看bin log文件的内容
mysql> show binlog events;
+----------------+-----+----------------+-----------+-------------+---------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+----------------+-----+----------------+-----------+-------------+---------------------------------------+
| dev-bin. | | Format_desc | | | Server ver: 5.7.-log, Binlog ver: |
| dev-bin. | | Previous_gtids | | | |
| dev-bin. | | Stop | | | |
+----------------+-----+----------------+-----------+-------------+---------------------------------------+
rows in set (0.00 sec) mysql> show binlog events in 'dev-bin.000004';
+----------------+------+----------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+----------------+------+----------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------------------+
| dev-bin. | | Format_desc | | | Server ver: 5.7.-log, Binlog ver: |
| dev-bin. | | Previous_gtids | | | |
| dev-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| dev-bin. | | Query | | | CREATE USER 'replication'@'192.168.1.51' IDENTIFIED WITH 'mysql_native_password' AS '*51125B3597BEE0FC43E0BCBFEE002EF8641B44CF' |
| dev-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| dev-bin. | | Query | | | GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.1.51' |
| dev-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| dev-bin. | | Query | | | flush privileges |
| dev-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| dev-bin. | | Query | | | use `sonar`; create table slave_t(
id int() not null, name varchar()
) |
| dev-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| dev-bin. | | Query | | | BEGIN |
| dev-bin. | | Table_map | | | table_id: (sonar.slave_t) |
| dev-bin. | | Write_rows | | | table_id: flags: STMT_END_F |
| dev-bin. | | Xid | | | COMMIT /* xid=178006 */ |
| dev-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| dev-bin. | | Query | | | create database slave_db |
+----------------+------+----------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------------------+
rows in set (0.13 sec) 查看当前数据库线程列表
【master-server】
mysql> SHOW PROCESSLIST \G
*************************** . row ***************************
Id:
User: root
Host: localhost
db: mysql
Command: Query
Time:
State: starting
Info: SHOW PROCESSLIST
*************************** . row ***************************
Id:
User: replication
Host: t-xi-orc01:
db: NULL
Command: Binlog Dump
Time:
State: Master has sent all binlog to slave; waiting for more updates
Info: NULL
*************************** . row ***************************
Id:
User: sonar
Host: localhost:
db: sonar
Command: Sleep
Time:
State:
Info: NULL
*************************** . row ***************************
Id:
User: sonar
Host: localhost:
db: sonar
Command: Sleep
Time:
State:
Info: NULL
*************************** . row ***************************
Id:
User: sonar
Host: localhost:
db: sonar
Command: Sleep
Time:
State:
Info: NULL
*************************** . row ***************************
Id:
User: sonar
Host: localhost:
db: sonar
Command: Sleep
Time:
State:
Info: NULL
rows in set (0.00 sec) 【slave-server】
mysql> SHOW PROCESSLIST \G
*************************** . row ***************************
Id:
User: root
Host: localhost
db: sonar
Command: Query
Time:
State: starting
Info: SHOW PROCESSLIST
*************************** . row ***************************
Id:
User: system user
Host:
db: NULL
Command: Connect
Time:
State: Waiting for master to send event
Info: NULL
*************************** . row ***************************
Id:
User: system user
Host:
db: NULL
Command: Connect
Time:
State: Slave has read all relay log; waiting for more updates
Info: NULL
rows in set (0.00 sec) 从库启动复制
mysql> START SLAVE;
从库停止复制
mysql> STOP SLAVE;
MySQL-5.7.20主从复制测试[20180110]的更多相关文章
- mysql主从复制测试
mysql主从复制测试: 1. 配置主服务器:在主库上面添加复制账号GRANT REPLICATION SLAVE on *.* to 'mark'@'%' identified by 'mark' ...
- MySQL+Amoeba实现数据库主从复制和读写分离
MySQL读写分离是在主从复制的基础上进一步通过在master上执行写操作,在slave上执行读操作来实现的.通过主从复制,master上的数据改动能够同步到slave上,从而保持了数据的一致性.实现 ...
- Mysql实现企业级数据库主从复制架构实战
场景 公司规模已经形成,用户数据已成为公司的核心命脉,一次老王一不小心把数据库文件删除,通过mysqldump备份策略恢复用了两个小时,在这两小时中,公司业务中断,损失100万,老王做出深刻反省,公司 ...
- 项目实战7—Mysql实现企业级数据库主从复制架构实战
Mysql实现企业级数据库主从复制架构实战 环境背景:公司规模已经形成,用户数据已成为公司的核心命脉,一次老王一不小心把数据库文件删除,通过mysqldump备份策略恢复用了两个小时,在这两小时中,公 ...
- MySQL/MariaDB数据库的主从复制
MySQL/MariaDB数据库的主从复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL复制概述 1>.传统扩展方式 垂直扩展(也叫向上扩展,Sacle ...
- mysql -- mysql基于ssl的主从复制
mysql基于ssl的主从复制由于mysql在复制过程中是明文的,所以就大大降低了安全性,因此需要借助于ssl加密来增加其复制的安全性. 主服务器node1:172.16.200.1从服务器node2 ...
- linux下mysql基于mycat做主从复制和读写分离之基础篇
Linux下mysql基于mycat实现主从复制和读写分离1.基础设施 两台虚拟机:172.20.79.232(主) 172.20.79.233(从) 1.1软件设施 mysql5.6.39 , my ...
- 1、MySql的安装和连接测试并给root用户赋密码
一.mysql数据库的安装 Windows下MySQL的配置 以 MySQL 5.1 免安装版为例, 下载 mysql-noinstall-5.1.69-win32.zip ( 官方下载页: http ...
- 使用sysbench 0.5 对mysql 进行性能、压力测试
sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.目前sysbench代码托管在launchpad上,项目地址:https://launc ...
随机推荐
- scss-@if指令
@if指令接受表达式和使用嵌套样式,无论表达式的结果只不过是false或null. 语法: @if expression { //CSS codes are written here } scss实例 ...
- 洛谷P4632 [APIO2018] New Home 新家(动态开节点线段树 二分答案 扫描线 set)
题意 题目链接 Sol 这题没有想象中的那么难,但也绝对不简单. 首先把所有的询问离线,按照出现的顺序.维护时间轴来处理每个询问 对于每个询问\((x_i, y_i)\),可以二分答案\(mid\). ...
- 转:如何利用已有的切片文件生成TPK
Tpk是ArcGIS 10.1即将推出的一种新的数据文件类型,主要是用于将切片文件打包形成离线地图包.Tpk可以在ArcGIS Runtime中作为切片底图被加载.在ArcGIS 10.1中Tpk的生 ...
- 03_Jsoup
[1.获取一个页面所有的链接] public static void main(String[] args) throws IOException { String url="http:// ...
- PhoneGap API介绍:Events
事件类型: backbutton deviceready menubutton pause resume searchbutton online offline backbutton 当用户在Andr ...
- .Net中会存在内存泄漏吗
所谓内存泄露就是指一个不再被程序使用的对象或变量一直被占据在内存中..Net 中有垃圾回收机制,它可以保证一对象不再被引用的时候,即对象编程了孤儿的时候,对象将自动被垃圾回收器从内存中清除掉.虽然.N ...
- centos7部署ethereum私有链
https://github.com/ethereum/go-ethereum/wiki http://book.8btc.com/books/6/ethereum/_book/public-chai ...
- sqlserver 带输出参数的存储过程
--创建存储过程create procedure proc_stu@sname varchar(20),@pwd varchar(50),@flag bit outputasif exists(sel ...
- Eclipse集成Maven(手工安装Maven且手工集成到Eclipse)
1.操作环境 操作系统:win8 64位 IDE:Helios Eclipse 1.8 JDK:1.6 2.资源准备 2.1 maven安装包: apache-maven-3.2.5-bin.zip ...
- p2psearcher绿色版使用方法
P2pSearcher大家应该很了解,p2p是一款基于P2P技术的资源搜索软件,基于先进的P2P搜索技术,可在瞬间搜遍全球ED2k网络资源,简单便捷的搜索到ED2K网络上共享的海量影音娱乐,学习资料等 ...