mysql运营_为线上运营Mysql数据库设置从库
一、为mysql运营主库添加一个repl 账号
[root@zabbix_server ~]# mysql -uroot -p -S /var/lib/mysql/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 15778982Server version:5.7.25MySQL Community Server (GPL)
Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.
mysql>
mysql> grant replication slave,replication client on *.* to 'repl'@'%' identified by 'xxxxxxxxxx';
二、修改主库my.cnf
增加以下字段
server_id=IP+PORT 标识服务器ID
log-bin=master-221 设置log_bin日志文件名
binlog_format=row 指定日志格式为row
server_id=693306log-bin=master-18-69binlog_format=row
三、重启主库mysql
停止mysql实例
[root@server-1 ~]# mysqladmin -uroot -p -S /home/mysql-5.7.26/mysql.sock shutdown
重启mysql实例
[root@server-1 ~]# mysqld_safe --defaults-file=/etc/mysql/my.cnf &
进入mysql
[root@server-1 ~]# mysql -uroot -p -S /home/mysql-5.7.26/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 4Server version:5.7.26-log Source distribution
Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.
mysql>
查看server_id变量
mysql> show variables like '%servier_id%';
Empty set (0.01sec)
mysql> show variables like '%server_id%';+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| server_id | 693306 |
| server_id_bits | 32 |
+----------------+--------+
2 rows in set (0.01sec)
mysql>
已经看到server_id变量已经成功设置。
四、修改从库my.cnf
添加server_id=IP+PORT
server_id=713306
五、重启mysql
[root@localhost mysql]# systemctl restart mysqld
[root@localhost mysql]#
进入mysql,查看server_id变量
[root@localhost data]# mysql -uroot -p -S /home/mysql-5.7.26/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 2Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.
mysql> show variables like '%server_id%';+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| server_id | 713306 |
| server_id_bits | 32 |
+----------------+--------+
2 rows in set (0.01sec)
mysql>
已经变成我们设置值了,
六、接下来执行从库命令
mysql>change master to-> master_host='172.28.18.69',-> master_port=3306,-> master_user='repl',-> master_password='Zaq1xsw@',-> master_log_file='master-18-69.000001',-> master_log_pos=419;
Query OK,0 rows affected, 2 warnings (0.10sec)
mysql>
这里的 master_log_file和master_log_pos值,我们可以在主库上运行如下命令得到
mysql>show master status\G;*************************** 1. row ***************************File: master-18-69.000001Position:419Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: d24d8a53-880d-11e9-b1f3-842b2b5cdc15:1-7,
ee3e292b-866b-11e9-9df8-14feb5dc2c77:1-23
1 row in set (0.00sec)
ERROR:
No query specified
mysql>
执行成功后,我们启动从库操作
mysql>start slave;
Query OK,0 rows affected (0.00sec)
mysql>
查询从库状态
mysql>show slave status\G;*************************** 1. row ***************************Slave_IO_State: Waitingformaster to send event
Master_Host:172.28.18.69Master_User: repl
Master_Port:3306Connect_Retry:60Master_Log_File: master-18-69.000001Read_Master_Log_Pos:1593Relay_Log_File: localhost-relay-bin.000002Relay_Log_Pos:1497Relay_Master_Log_File: master-18-69.000001Slave_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:0Last_Error:
Skip_Counter:0Exec_Master_Log_Pos:1593Relay_Log_Space:1708Until_Condition: None
Until_Log_File:
Until_Log_Pos:0Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:0Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:0Last_IO_Error:
Last_SQL_Errno:0Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:693306Master_UUID: ee3e292b-866b-11e9-9df8-14feb5dc2c77
Master_Info_File:/home/mysql-5.7.26/data/master.infoSQL_Delay:0SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waitingfor moreupdates
Master_Retry_Count:86400Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: d24d8a53-880d-11e9-b1f3-842b2b5cdc15:1-79,
ee3e292b-866b-11e9-9df8-14feb5dc2c77:1-15Auto_Position:0Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:1 row in set (0.00sec)
ERROR:
No query specified
mysql>
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
从库启动成功,同步成功
Exec_Master_Log_Pos: 1593
目前同步到主库数据库文件位置:1593
在主库上进入mysql,并查看主库状态
mysql>show master status\G;*************************** 1. row ***************************File: master-18-69.000001Position:1593Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: d24d8a53-880d-11e9-b1f3-842b2b5cdc15:1-7,
ee3e292b-866b-11e9-9df8-14feb5dc2c77:1-23
1 row in set (0.00sec)
ERROR:
No query specified
mysql>
同样主库文件最后位置也是1593,说明从库同步设置完毕
mysql运营_为线上运营Mysql数据库设置从库相关推荐
- mysql len hex asc_线上频出MySQL死锁问题!分享一下自己教科书般的排查和分析过程!...
本文主要是讲过程与思路,从手上的日志来反推故障现场,最后模拟出事故现场.没有过度讲解理论的一些知识,主要是偏分析. 文章参考的理论知识在最后,同时也将本次案例提交 ISSUE 给:https://gi ...
- 认识mysql总结_从根上理解Mysql - 读后个人总结1-搜云库
初识 MySQL 通信介绍 MySQL 也是典型的 C / S 模型,分为客户端及服务端,服务端一般部署在远端服务器中,也可以部署至本地,然后客户端跟服务端通信则可以使用依赖网络的 TCP 长连接或 ...
- ubuntu mysql 优化_在Ubuntu上使用MySQL设置远程数据库优化站点性能
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 介绍 随着您的应用程序或网站的增长,您可能已经超出了当前的服务器设置.如果您在同一台计算机上托管Web服务器和数据库后端,最好将这两个功能分 ...
- mysql线上教程_线上环境mysql主从同步的搭建过程
之前搭建过一套主从同步的mysql集群,但是是基于新数据库,而这次线上环境要升级成主从同步的集群,记录一下升级过程和中间遇到的各种问题. 由于是直接对线上数据库进行修改,因此要保证对线上环境造成尽量小 ...
- 门店私域运营,突围线上冲击
线下的实体零售门店想要打破线上冲击,那就要改变现状,先突破固有的思维模式,我们知道线上的效率要远高于大部分的线下零售行业的,尤其是近年来,线上电商行业的迅速崛起,逐渐霸占了人们的消费方式,也因此一些线 ...
- 智能家居实体门店老板如何搭建线上运营体系,实现业绩倍增?
作者 | 莫文 编辑 | 小智 出品:智哪儿 zhinaer.cn 前几天是24节气的第3个节气"惊蛰",<夏小正>曰:"万物出乎震,震为雷,故曰惊蛰.是 ...
- 远程主机访问mysql权限_如何给远程主机开启mysql远程登录权限
# 如何给远程主机开启mysql远程登录权限 > 在千锋学习PHP的有些学员会在阿里或者腾讯云去购买自己的云服务器.在初级阶段的项目上线时会遇到一个问题,就是无法使用远程连接工具操作自己线上的m ...
- MySQL入门_实战3_创建和删除数据库
MySQL入门_实战系列文章目录 MySQL入门_实战1 MYSQL安装和卸载 MySQL入门_实战2 MYSQL的登录和断开以及SQL查询常见问题 文章目录 MySQL入门_实战系列文章目录 前言 ...
- 线上故障之-数据库问题
线上故障之-数据库问题 数据库问题概述 索引: 高可用 一些需要注意的事项 处理问题的一些技巧 一般大厂数据库规约 一.基础规范 二.命名规范 三.表设计规范 四.字段设计规范 五.索引设计规范 死锁 ...
最新文章
- Jenkins+SonarQube6.5.5+SonarScanner2.5代码质量管理平台
- lwuit ---一些细节疑难杂症整理笔记
- 用sqoop把hdfs数据存储到mysql报错,Job job_1566707990804_0002 failed with state FAILED due to: Tas k failed
- SLF4J:Failed to load class org.slf4j.impl.StaticLoggerBinder
- ab压力 failed_ab测试时结果显示大量Request failed的情况分析
- Cesium工作笔记001---地理位置信息js展示框架_Cesium介绍
- 关于蓝桥杯竞赛考试的一些信息~
- ATM系统之问题描述与词汇表
- 大数据分析的作用与注意事项
- Oracle 11g ora 15018,OracleASM错误之--ORA-15031、ORA-15014
- mac/linux下java项目使用本机自带ssh和scp命令,自动复制上传并部署的脚本
- 微信html5视频播放器,解决微信h5页面视频播放问题实例
- [Maven实战-许晓斌]-[第二章]-2.6 NetBeans上面安装Maven插件
- Tableau desktop 复制交叉表作为数据源
- win10 你的手机
- GPRS、433、Wifi、Zigbee模块概念和区别
- 继阿里巴巴之后,饿了么也出事了,究竟发生了什么?
- 决策树鸢尾花算法讲解
- 心里窝火无语的图片_窝火的心情说说图片
- 对于机械键盘的一些见解(转载)
热门文章
- mybatis学习(8):The server time zone value '???ú±ê×??±??' is unrecognized or represents more
- 实例47:python
- SRZoo--深度学习图像超分辨率工具
- 5月份 Github 上最热的十个 Python 项目,从Debug工具到AI水军、量化交易系统。
- python2和python3解释器的区别
- Dockerfile语法
- NYOJ题目 263 精挑细选
- 回顾2009,展望2010
- 11-11 又是一年光棍节!
- aix 到 linux的网络,DB2从AIX server上转移(迁移)到linux上-通信/网络-与非网