基于Canal和Kafka实现MySQL的Binlog近实时同步 (2)

选用的是最新版的MySQL8.x社区版,下载CentOS7适用的rpm包:

cd /data/mysql wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm // 下载完毕之后 sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

此时列举一下yum仓库里面的MySQL相关的包:

[root@localhost mysql]# yum repolist all | grep mysql mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community disabled mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - disabled mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 141 mysql-connectors-community-source MySQL Connectors Community - disabled mysql-tools-community/x86_64 MySQL Tools Community enabled: 105 mysql-tools-community-source MySQL Tools Community - Sourc disabled mysql-tools-preview/x86_64 MySQL Tools Preview disabled mysql-tools-preview-source MySQL Tools Preview - Source disabled mysql55-community/x86_64 MySQL 5.5 Community Server disabled mysql55-community-source MySQL 5.5 Community Server - disabled mysql56-community/x86_64 MySQL 5.6 Community Server disabled mysql56-community-source MySQL 5.6 Community Server - disabled mysql57-community/x86_64 MySQL 5.7 Community Server disabled mysql57-community-source MySQL 5.7 Community Server - disabled mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 161 mysql80-community-source MySQL 8.0 Community Server - disabled

编辑/etc/yum.repos.d/mysql-community.repo文件([mysql80-community]块中enabled设置为1,其实默认就是这样子,不用改,如果要选用5.x版本则需要修改对应的块):

[mysql80-community] name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

然后安装MySQL服务:

sudo yum install mysql-community-server

这个过程比较漫长,因为需要下载和安装5个rpm安装包(或者是所有安装包组合的压缩包mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar)。如果网络比较差,也可以直接从官网手动下载后安装:

基于Canal和Kafka实现MySQL的Binlog近实时同步

// 下载下面5个rpm包 common --> libs --> libs-compat --> client --> server mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-client mysql-community-server // 强制安装 rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm --force --nodeps rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm --force --nodeps rpm -ivh mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm --force --nodeps rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm --force --nodeps rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm --force --nodeps

安装完毕之后,启动MySQL服务,然后搜索MySQL服务的root账号的临时密码用于首次登陆(mysql -u root -p):

// 启动服务,关闭服务就是service mysqld stop service mysqld start // 查看临时密码 cat /var/log/mysqld.log [root@localhost log]# cat /var/log/mysqld.log 2020-03-02T06:03:53.996423Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 22780 2020-03-02T06:03:57.321447Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >kjYaXENK6li 2020-03-02T06:04:00.123845Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 22834 // 登录临时root用户,使用临时密码 [root@localhost log]# mysql -u root -p

接下来做下面的操作:

修改root用户的密码:ALTER USER \'root\'@\'localhost\' IDENTIFIED BY \'QWqw12!@\';(注意密码规则必须包含大小写字母、数字和特殊字符)

更新root的host,切换数据库use mysql;,指定host为%以便可以让其他服务器远程访问UPDATE USER SET HOST = \'%\' WHERE USER = \'root\';

赋予\'root\'@\'%\'用户,所有权限,执行GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'%\';

改变root\'@\'%用户的密码校验规则以便可以使用Navicat等工具访问:ALTER USER \'root\'@\'%\' IDENTIFIED WITH mysql_native_password BY \'QWqw12!@\';

基于Canal和Kafka实现MySQL的Binlog近实时同步

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyspdz.html