安装、配置mysql、开启主从同步

# *** 关闭防火墙或禁用开机启动 ***
 systemctl stop firewalld 
 systemctl disable firewalld

安装详细教程

 # 下载
 wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
 # 解压
 rpm -ivh mysql80-community-release-el7-3.noarch.rpm 
 # 安装
 yum -y install mysql-server
 systemctl start mysqld
 # 安装失败:如果出现" Failing package is: mysql-community-common-8.0.33-1.el7.x86_64 
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql"这句话请执行下面代码  
 # rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
 # 再次安装
 yum -y install mysql-server
 systemctl start mysqld
 systemctl status mysqld
 systemctl enable mysqld

查看初始密码

# 初始化(不执行也是可以的)
# mysqld --initialize --console
# 获取初始化密码(localhost:后面的就是初始密码)
cat /var/log/mysqld.log | grep localhost

配置

登录并修改初始密码:

mysql -uroot -h 127.0.0.1 -paddad,dsad
修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin123456!';

允许root账户IP登录:

use mysql;
update user set host='%' where user='root';
flush privileges;
GRANT ALL ON *.* TO 'root'@'%';
flush privileges;

开启MySql允许基于BinLog文件主从复制

Canal的核心原理也是相当于把自己当成MySql的一个从节点,然后去订阅主节点的BinLog日志。

修改配置文件/etc/my.cnf

# 添加这一行就ok
log-bin=mysql-bin
# 选择row模式
binlog-format=ROW
# 配置mysql replaction需要定义,不能和canal的slaveId重复
server_id=1

开启log_bin

show variables like 'log_bin';
查询MySql是否开启了log_bin,没有开启log_bin的值是OFF,开启之后是ON。

添加cannl账号

C:\dev-env\mysql-5.7.36-winx64\bin>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36-log

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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 clear the current input statement.

mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password=password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> drop user 'canal'@'%';
ERROR 1396 (HY000): Operation DROP USER failed for 'canal'@'%' #注意因为此时还没有canal用户,所以会报错。如果先创建了canal用户再删除则不会报错

mysql> CREATE USER 'canal'@'%' IDENTIFIED BY 'canal';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'canal'@'%' identified by 'canal';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

删除binlog

C:\dev-env\mysql-5.7.36-winx64\bin>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 147
Server version: 5.7.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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 clear the current input statement.

mysql> use mysql;
Database changed
mysql> reset master;
Query OK, 0 rows affected (0.03 sec)

mysql> exit;
Bye
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心有城府,腹有良谋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值