# *** 关闭防火墙或禁用开机启动 ***
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