8.【canal】canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-mysql安装

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-mysql安装

1.安装前准备

1.1 操作系统(cenos7.9 x86)

#查看/etc/redhat-release文件cat /etc/redhat-releaseCentOS Linux release 7.9.2009 (Core)#查看/proc/version文件# proc 为process的缩写,里面存放与内核相关的文件cat /proc/versionLinux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) )#1 SMP Mon Oct 19 16:18:59 UTC 2020#使用uname -a 命令uname -aLinux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
复制代码

1.2 工具版本选择

mysql: MySQL-5.7

rocketMQ:rocketmq-all-4.9.3

canal版本:canal.deployer-1.1.5.tar.gz

2 安装环境搭建

2.1 MySQL安装

参考文档: zhuanlan.zhihu.com/p/87069388

(1)检查是否已经安装过mysql,执行命令

[root@localhost software]# rpm -qa | grep mysql[root@localhost software]#
复制代码

从结果来看,当前机器没有安装mysql。可以直接安装MySQL,如果需要卸载旧版,操作如下:

[root@localhost /]#rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64#再次执行查询命令,查看是否删除[root@localhost /]# rpm -qa | grep mysql#查询所有Mysql对应的文件夹[root@localhost /]# whereis mysqlmysql: /usr/bin/mysql /usr/include/mysql[root@localhost lib]# find / -name mysql/data/mysql/data/mysql/mysql#删除相关目录或文件[root@localhost /]#  rm -rf /usr/bin/mysql /usr/include/mysql /data/mysql /data/mysql/mysql #验证是否删除完毕[root@localhost /]# whereis mysqlmysql:[root@localhost /]# find / -name mysql[root@localhost /]#
复制代码

(2)安装mysql

从官网下载用于Linux的Mysql安装包

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz--2022-04-25 23:11:17--  https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gzResolving dev.mysql.com (dev.mysql.com)... 137.254.60.11Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.HTTP request sent, awaiting response... 302 FoundLocation: https://cdn.mysql.com//archives/mysql-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz [following]--2022-04-25 23:11:18--  https://cdn.mysql.com//archives/mysql-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gzResolving cdn.mysql.com (cdn.mysql.com)... 23.56.1.19Connecting to cdn.mysql.com (cdn.mysql.com)|23.56.1.19|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 644930593 (615M) [application/x-tar-gz]Saving to: ‘mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz’100%[=============================================] in 6m0s2022-04-25 23:17:19 (1.71 MB/s) - ‘mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz’ saved [644930593/644930593]
复制代码

解压,赋权限,切换用户到anchu

#解压当前目录[root@localhost software]# pwd/home/anchu/software[root@localhost software]# lscanal  canal.deployer-1.1.5.tar.gz  canal.example-1.1.5.tar.gz  mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz[root@localhost software]# tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz #赋权给anchu[root@localhost software]# chown -R anchu:anchu mysql-5.7.24-linux-glibc2.12-x86_64#切换到anchu
[root@localhost software]# su anchu#重命名目录为 mysql-5.7.24[anchu@localhost software]$ mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql-5.7.24[anchu@localhost software]$ [anchu@localhost software]$ lscanal  canal.deployer-1.1.5.tar.gz  canal.example-1.1.5.tar.gz  mysql-5.7.24  mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
#设置mysql环境变量[anchu@localhost software]$ cd mysql-5.7.24/[anchu@localhost mysql-5.7.24]$ cd bin[anchu@localhost bin]$ pwd/home/anchu/software/mysql-5.7.24/bin[anchu@localhost bin]$ vi ~/.bash_profile [anchu@localhost bin]$ lsinnochecksum    myisam_ftdump  my_print_defaults  mysqlbinlog                 mysql_config         mysqld-debug  mysqldump       mysqlimport       mysqlpump                  mysqlslap            mysql_tzinfo_to_sql  perror     resolve_stack_dumplz4_decompress  myisamlog      mysql              mysqlcheck                  mysql_config_editor  mysqld_multi  mysqldumpslow   mysql_install_db  mysql_secure_installation  mysql_ssl_rsa_setup  mysql_upgrade        replace    zlib_decompressmyisamchk       myisampack     mysqladmin         mysql_client_test_embedded  mysqld               mysqld_safe   mysql_embedded  mysql_plugin      mysqlshow                  mysqltest_embedded   mysqlxtest           resolveip[anchu@localhost bin]$ pwd/home/anchu/software/mysql-5.7.24/bin
[anchu@localhost bin]$ echo 'MYSQL_HOME=/home/anchu/software/mysql-5.7.24/' >>~/.bash_profile[anchu@localhost bin]$ echo 'PATH=$PATH:$MYSQL_HOME/bin' >>~/.bash_profile[anchu@localhost bin]$ echo 'export PATH'  >>~/.bash_profile[anchu@localhost bin]$ source ~/.bash_profile [anchu@localhost bin]$ mysql --versionmysql  Ver 14.14 Distrib 5.7.24, for linux-glibc2.12 (x86_64) using  EditLine wrapper
复制代码

创建数据目录初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)\

[anchu@localhost mysql-5.7.24]$ pwd/home/anchu/software/mysql-5.7.24[anchu@localhost mysql-5.7.24]$ mkdir data[anchu@localhost mysql-5.7.24]$ cd data[anchu@localhost data]$ pwd/home/anchu/software/mysql-5.7.24/data ./mysqld --initialize --user=anchu --datadir=/home/anchu/software/mysql-5.7.24/data --basedir=/home/anchu/software/mysql-5.7.24/
 [anchu@localhost mysql-5.7.24]$ mysqld --initialize --user=anchu --datadir=/home/anchu/software/mysql-5.7.24/data --basedir=/home/anchu/software/mysql-5.7.24/2022-04-26T07:26:58.470872Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2022-04-26T07:26:58.471169Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)2022-04-26T07:26:58.471516Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2022-04-26T07:26:59.096129Z 0 [Warning] InnoDB: New log files created, LSN=457902022-04-26T07:26:59.272923Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2022-04-26T07:26:59.346943Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4253d31b-c532-11ec-9f60-000c29924945.2022-04-26T07:26:59.358828Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2022-04-26T07:26:59.381263Z 1 [Note] A temporary password is generated for root@localhost: )wR#VWfgd0O<
复制代码

由上可知:密码为)wR#VWfgd0O<

编辑配置文件my.cnf,添加配置如下:

[anchu@localhost bin]$  su root[root@localhost bin]#  vi /etc/my.cnf
[mysqld]#datadir=/var/lib/mysql#socket=/var/lib/mysql/mysql.sockdatadir=/home/anchu/software/mysql-5.7.24/datasocket=/home/anchu/software/mysql-5.7.24/data/mysql.sockport=3306sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLESmax_connections=400innodb_file_per_table=1#表名大小写不明感,敏感为1#lower_case_table_names=0  表名存储为给定的大小和比较是区分大小写的#lower_case_table_names = 1  表名存储在磁盘是小写的,但是比较的时候是不区分大小写#lower_case_table_names=2 表名存储为给定的大小写但是比较的时候是小写的#unix,linux下lower_case_table_names默认值为 0 .Windows下默认值是 1 .Mac OS X下默认值是 2lower_case_table_names=1# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.# If you need to run mysqld under a different user or group,# customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]log-error=/home/anchu/software/mysql-5.7.24/data/mariadb.logpid-file=/home/anchu/software/mysql-5.7.24/data/mariadb.pid## include all files from the config directory#!includedir /etc/my.cnf.d
[root@localhost bin]# cp /etc/my.cnf /home/anchu/software/mysql-5.7.24/[root@localhost bin]# chown anchu:anchu /home/anchu/software/mysql-5.7.24/my.cnf
复制代码

(3)启动mysql服务器

[anchu@localhost support-files]$ su anchuPassword: [anchu@localhost support-files]$ pwd/home/anchu/software/mysql-5.7.24/support-files[anchu@localhost support-files]$ mysql.server startbash: mysql.server: command not found...[anchu@localhost support-files]$ lsmagic  mysqld_multi.server  mysql-log-rotate  mysql.server[anchu@localhost support-files]$ ./mysql.server start./mysql.server: line 239: my_print_defaults: command not found./mysql.server: line 259: cd: /usr/local/mysql: No such file or directoryStarting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)#通过mysqld_safe启动[anchu@localhost mysql-5.7.24]$  /bin/sh /home/anchu/software/mysql-5.7.24/bin/mysqld_safe --defaults-file=/home/anchu/software/mysql-5.7.24/my.cnf 2>&1 > /dev/null & [1] 81651#查看进程[anchu@localhost mysql-5.7.24]$ ps -ef|grep mysqlanchu     81651  80040  0 19:44 pts/1    00:00:00 /bin/sh /home/anchu/software/mysql-5.7.24/bin/mysqld_safe --defaults-file=/home/anchu/software/mysql-5.7.24/my.cnfanchu     81841  81651 11 19:44 pts/1    00:00:00 /home/anchu/software/mysql-5.7.24/bin/mysqld --defaults-file=/home/anchu/software/mysql-5.7.24/my.cnf --basedir=/home/anchu/software/mysql-5.7.24 --datadir=/home/anchu/software/mysql-5.7.24/data --plugin-dir=/home/anchu/software/mysql-5.7.24/lib/plugin --log-error=/home/anchu/software/mysql-5.7.24/data/mariadb.log --pid-file=/home/anchu/software/mysql-5.7.24/data/mariadb.pid --socket=/home/anchu/software/mysql-5.7.24/data/mysql.sock --port=3306
[anchu@localhost support-files]$ ps -ef|grep mysqldanchu     81651  80040  0 19:44 pts/1    00:00:00 /bin/sh /home/anchu/software/mysql-5.7.24/bin/mysqld_safe --defaults-file=/home/anchu/software/mysql-5.7.24/my.cnfanchu     81841  81651  0 19:44 pts/1    00:00:00 /home/anchu/software/mysql-5.7.24/bin/mysqld --defaults-file=/home/anchu/software/mysql-5.7.24/my.cnf --basedir=/home/anchu/software/mysql-5.7.24 --datadir=/home/anchu/software/mysql-5.7.24/data --plugin-dir=/home/anchu/software/mysql-5.7.24/lib/plugin --log-error=/home/anchu/software/mysql-5.7.24/data/mariadb.log --pid-file=/home/anchu/software/mysql-5.7.24/data/mariadb.pid --socket=/home/anchu/software/mysql-5.7.24/data/mysql.sock --port=3306
复制代码

登录mysql,修改密码(密码为步骤5生成的临时密码)  123456

[anchu@localhost support-files]$ mysql -u root -P 3306 -h 127.0.0.1  -pEnter password:   )wR#VWfgd0O<Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 13Server version: 5.7.24Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password for root@localhost = password('123456');Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql>exit 
#重新登陆验证密码[anchu@localhost support-files]$ mysql -u root -P 3306 -h 127.0.0.1  -pEnter password:   123456
复制代码

(4)开放远程连接,测试应用

mysql>use mysql;^Cmysql> use anchu;ERROR 1049 (42000): Unknown database 'anchu'mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A
Database changedmysql> update user set user.Host='%' where user.User='root';Query OK, 1 row affected (0.03 sec)Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
mysql> exit
#测试[anchu@localhost support-files]$ mysql -u root -P 3306 -h 192.168.120.110 -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 17Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show tables;ERROR 1046 (3D000): No database selectedmysql> create database test;Query OK, 1 row affected (0.00 sec)
mysql> connect test;Connection id:    20Current database: test
mysql> show tables;Empty set (0.01 sec)mysql> create table test(id int(10),name varchar(10));Query OK, 0 rows affected (0.17 sec)
mysql> show tables;+----------------+| Tables_in_test |+----------------+| test           |+----------------+1 row in set (0.00 sec)
复制代码

至此,mysql安装结束。


相关实践学习
Serverless极速搭建Hexo博客
本场景介绍如何使用阿里云函数计算服务命令行工具快速搭建一个Hexo博客。
相关文章
|
6天前
|
Java 数据库连接 测试技术
SpringBoot入门(4) - 添加内存数据库H2
SpringBoot入门(4) - 添加内存数据库H2
28 4
SpringBoot入门(4) - 添加内存数据库H2
|
9天前
|
Java 数据库连接 测试技术
SpringBoot入门(4) - 添加内存数据库H2
SpringBoot入门(4) - 添加内存数据库H2
20 2
SpringBoot入门(4) - 添加内存数据库H2
|
1天前
|
Java 数据库连接 测试技术
SpringBoot入门(4) - 添加内存数据库H2
SpringBoot入门(4) - 添加内存数据库H2
34 13
|
18天前
|
关系型数据库 MySQL Linux
Docker安装Mysql5.7,解决无法访问DockerHub问题
当 Docker Hub 无法访问时,可以通过配置国内镜像加速来解决应用安装失败和镜像拉取超时的问题。本文介绍了如何在 CentOS 上一键配置国内镜像加速,并成功拉取 MySQL 5.7 镜像。
157 2
Docker安装Mysql5.7,解决无法访问DockerHub问题
|
2天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。通过具体案例,读者可以了解如何准备环境、下载源码、编译安装、配置服务及登录 MySQL。编译源码安装虽然复杂,但提供了更高的定制性和灵活性,适用于需要高度定制的场景。
11 3
|
3天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。
本文介绍了在 CentOS 7 中通过编译源码安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。内容涵盖准备工作、下载源码、编译安装、配置服务、登录设置及实践心得,帮助读者根据需求选择最适合的安装方法。
8 2
|
4天前
|
存储 SQL 关系型数据库
2024Mysql And Redis基础与进阶操作系列(1)作者——LJS[含MySQL的下载、安装、配置详解步骤及报错对应解决方法]
Mysql And Redis基础与进阶操作系列(1)之[MySQL的下载、安装、配置详解步骤及报错对应解决方法]
|
5天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据需求选择最合适的方法。通过具体案例,展示了编译源码安装的灵活性和定制性。
30 2
|
9天前
|
存储 人工智能 Java
Neo4j从入门到精通:打造高效知识图谱数据库 | AI应用开发
在大数据和人工智能时代,知识图谱作为一种高效的数据表示和查询方式,逐渐受到广泛关注。本文从入门到精通,详细介绍知识图谱及其存储工具Neo4j,涵盖知识图谱的介绍、Neo4j的特点、安装步骤、使用方法(创建、查询)及Cypher查询语言的详细讲解。通过本文,读者将全面了解如何利用Neo4j处理复杂关系数据。【10月更文挑战第14天】
43 6
|
17天前
|
SQL Oracle 关系型数据库
安装最新 MySQL 8.0 数据库(教学用)
安装最新 MySQL 8.0 数据库(教学用)
86 4