#!/bin/bash
export master_ip=192.168.7.206
export slave_ip=192.168.7.207
export root_passwd=123456
echo '#1.取master主机ip的后三位作为master的server_id'
export master_server_id=`echo $master_ip |awk -F . '{print $4}'`
echo '#2.取slave主机ip的后三位作为slave的server_id'
export slave_server_id=`echo $slave_ip |awk -F . '{print $4}'`
echo '#3.取出master主库的postion'
postion_num=$(ssh -Tq $master_ip <<eof
mysql -uroot -e 'show master status\G' 2>/dev/null|grep Position |cut -f2 -d :
--#mysql -uroot -p123456 -h$master_ip -e 'show master status\G' 2>/dev/null|grep Position |cut -f2 -d :
eof
)
echo '#4.取出master主库的log_name'
log_name=$(ssh -Tq $master_ip <<eof
mysql -uroot -p123456 -e 'show master status\G' 2>/dev/null|grep File |cut -f2 -d :
eof
)
echo '#5.事先修改master主库的server_id'
echo $master_server_id
#ssh ${master_ip} <<EOF
mysql -uroot -h$master_ip <<eof
--#set global server_id=echo $master_ip | cut -b 11,12,13
set global server_id=$master_server_id;
eof
service mysql restart
echo '#6.事先修改slave从库的server_id'
echo $slave_server_id
mysql -uroot -h$slave_ip <<eof
set global server_id=$slave_server_id;
eof
echo '#7.slave库设置密码和配置'
#ssh -Tq `${slave_ip}` <<EOF
mysql -uroot -h192.168.7.207 <<eof
use mysql;
stop slave;
select sysdate();
flush privileges;
#set password = password("${root_passwd}");
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${root_passwd}';
GRANT ALL PRIVILEGES ON *.* TO 'root'@localhost IDENTIFIED BY '${root_passwd}';
--#change master to master_host='192.168.7.206',master_port=3309,master_user='root',master_password='123456', master_log_file='bin.000017',master_log_pos=8888;
--#change master to master_host='192.168.7.206',master_port=3309,master_user='root',master_password='123456', master_log_file='${log_name}',master_log_pos=${postion_num};
flush privileges;
eof
echo '#8.slave库做chang master 操作'
ssh -Tq $master_ip <<EOF
service mysql restart
EOF
ssh -Tq $slave_ip <<EOF
service mysql restart
EOF
export master_ip=192.168.7.206
export slave_ip=192.168.7.207
echo '#3.取出master主库的postion'
postion_num=$(ssh -Tq $master_ip <<eof
--#mysql -uroot -e 'show master status\G' 2>/dev/null|grep Position |cut -f2 -d :
mysql -uroot -p123456 -h$master_ip -e 'show master status\G' 2>/dev/null|grep Position |cut -f2 -d :
eof
)
echo '#4.取出master主库的log_name'
log_name=$(ssh -Tq $master_ip <<eof
mysql -uroot -p123456 -e 'show master status\G' 2>/dev/null|grep File |cut -f2 -d :
eof
)
echo $postion_num
echo $log_name
mysql -uroot -h192.168.7.207 <<eof
--#change master to master_host='192.168.7.206',master_port=3309,master_user='root',master_password='123456', master_log_file='bin.000017',master_log_pos=8888;
change master to master_host='${master_ip}',master_port=3309,master_user='root',master_password='123456',master_log_file='${log_name}',master_log_pos=${postion_num};;
start slave;
select sysdate();
eof
exit;
- 这次一定要教会你搭建Redis集群和MySQL主从同步(非Docker)
前言 一直都想自己动手搭建一个Redis集群和MySQL的主从同步,当然不是依靠Docker的一键部署(虽然现在企业开发用的最多的是这种方式),所以本文就算是一个教程类文章吧,但在动手搭建之前,会先聊 ...
- zabbix3.0.4监控mysql主从同步
zabbix3.0.4监控mysql主从同步 1.监控mysql主从同步原理: 执行一个命令 mysql -u zabbix -pzabbix -e 'show slave status\G' 我们在 ...
- MySQL主从同步几个文件
MySQL主从同步: M锁表 M导出S导入 M解锁 M建同步帐号 S获取点位:产生master.info S开启同步 3306: mysql-bin.0000x mysql-bin.index ...
- 监控mysql主从同步状态脚本
监控mysql主从同步状态脚本 示例一: cat check_mysql_health #!/bin/sh slave_is=($(mysql -S /tmp/mysql3307.sock -uroo ...
- Linux下MySQL主从同步配置
Centos6.5 MySQL主从同步 MySQL版本5.6.25 主服务器:centos6.5 IP:192.168.1.101 从服务器:centos6.5 IP:192.168.1.102 一. ...
- Mysql主从同步(复制)
目录: mysql主从同步定义 主从同步机制 配置主从同步 配置主服务器 配置从服务器 使用主从同步来备份 使用mysqldump来备份 备份原始文件 ...
- MySQL主从同步原理 部署【转】
一.主从的作用:1.可以当做一种备份方式2.用来实现读写分离,缓解一个数据库的压力二.MySQL主从备份原理master 上提供binlog ,slave 通过 I/O线程从 master拿取 bin ...
- shell脚本修复MySQL主从同步
发布:thebaby 来源:net [大 中 小] 分享一例shell脚本,用于修改mysql的主从同步问题,有需要的朋友参考下吧. 一个可以修改mysql主从同步的shell脚本. 例子 ...
- nagios 实现Mysql 主从同步状态的监控
一.系统环境 主机名 IP nagios 192.168.15.111 mysql_s 192.168.15.21 二.操作步骤 2.1 mysql_s端的配置 2.1.1 编写check_mysql ...
随机推荐
- printf和cout的区别详述
https://blog.csdn.net/ysayk/article/details/50959909
- Jenkins-Publish HTML reports
创建job:testreport 在job中添加: 在Jenkins服务器上: 创建目录: .jenkins/jobs/{job名称}/workspace/htmlreports 注:此处job ...
- js字符串与十六进制相互转换
1.字符串(汉字)转换为十六进制 主要使用字符串.charCodeAt()方法,此方法返回一个字符的Unicode值,再用toString(16)方法,该方法是先将数字对象转换为二进制,再把二进制转化 ...
- Centos7 安装python3.7.2
下载python3.7.2源码 wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz 下载完后对压缩包解压缩 tar -xf Py ...
- Mysql一些常用语句
1.查询表创建的时间: SELECT CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERETABLE_NAME='TableName'
- STL_string.【转】C++中int、string等常见类型转换
ZC:#include <sstream> ZC:貌似还有 istringstream 和 ostringstream ... https://www.cnblogs.com/gaobw/ ...
- try....fail....catch...Assert 模式的测试, fail是Junit中的功能
try { // 反射读取properties文件 new BufferedReader(new FileReader(myConfigPath[4])); //上面没有抛出异常就是执行fail, / ...
- Transactional cannot be resolved to a type
SpringBoot整合Mybatis时遇到“ Transactional cannot be resolved to a type ” ,以为是没有导入相应的包 “ import org.sprin ...
- 浅谈Java简单实现的生产者与消费者问题
一.面对生产者和消费者的问题,首先我们得明白几点: 生产者:生产数据:消费者:消费数据.消费者在没有数据可供消费的情况下,不能消费:生产者在原数据没有被消费掉的情况下,不能生产新数据.假设,数据空间只 ...
- PHP如何安装redis扩展(Windows下)
PHP如何安装redis扩展(Windows下) 一.总结 一句话总结:下载扩展的dll,放入指定文件夹(php对应的扩展的目录php/ext),在配置文件php.ini中注册dll 尽量不要选择最新 ...