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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 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博客。
相关文章
|
19天前
|
消息中间件 Linux API
centos7 安装rabbitmq自定义版本及配置
centos7 安装rabbitmq自定义版本及配置
|
21天前
|
弹性计算 关系型数据库 数据库
手把手带你从自建 MySQL 迁移到云数据库,一步就能脱胎换骨
阿里云瑶池数据库来开课啦!自建数据库迁移至云数据库 RDS原来只要一步操作就能搞定!点击阅读原文完成实验就可获得一本日历哦~
|
25天前
|
关系型数据库 MySQL 数据库
RDS MySQL灾备服务协同解决方案构建问题之数据库备份数据的云上云下迁移如何解决
RDS MySQL灾备服务协同解决方案构建问题之数据库备份数据的云上云下迁移如何解决
|
3天前
|
存储 SQL 关系型数据库
一篇文章搞懂MySQL的分库分表,从拆分场景、目标评估、拆分方案、不停机迁移、一致性补偿等方面详细阐述MySQL数据库的分库分表方案
MySQL如何进行分库分表、数据迁移?从相关概念、使用场景、拆分方式、分表字段选择、数据一致性校验等角度阐述MySQL数据库的分库分表方案。
一篇文章搞懂MySQL的分库分表,从拆分场景、目标评估、拆分方案、不停机迁移、一致性补偿等方面详细阐述MySQL数据库的分库分表方案
|
14天前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
2天前
|
存储 SQL 关系型数据库
使用MySQL Workbench进行数据库备份
【9月更文挑战第13天】以下是使用MySQL Workbench进行数据库备份的步骤:启动软件后,通过“Database”菜单中的“管理连接”选项配置并选择要备份的数据库。随后,选择“数据导出”,确认导出的数据库及格式(推荐SQL格式),设置存储路径,点击“开始导出”。完成后,可在指定路径找到备份文件,建议定期备份并存储于安全位置。
28 11
|
1天前
|
SQL 监控 关系型数据库
MySQL数据库中如何检查一条SQL语句是否被回滚
检查MySQL中的SQL语句是否被回滚需要综合使用日志分析、事务状态监控和事务控制语句。理解和应用这些工具和命令,可以有效地管理和验证数据库事务的执行情况,确保数据的一致性和系统的稳定性。此外,熟悉事务的ACID属性和正确设置事务隔离级别对于预防数据问题和解决事务冲突同样重要。
9 2
|
22天前
|
人工智能 小程序 关系型数据库
【MySQL】黑悟空都掌握的技能,数据库隔离级别全攻略
本文以热门游戏《黑神话:悟空》为契机,深入浅出地解析了数据库事务的四种隔离级别:读未提交、读已提交、可重复读和串行化。通过具体示例,展示了不同隔离级别下的事务行为差异及可能遇到的问题,如脏读、不可重复读和幻读等。此外,还介绍了在MySQL中设置隔离级别的方法,包括全局和会话级别的调整,并通过实操演示了各隔离级别下的具体效果。本文旨在帮助开发者更好地理解和运用事务隔离级别,以提升数据库应用的一致性和性能。
101 2
【MySQL】黑悟空都掌握的技能,数据库隔离级别全攻略
|
8天前
|
SQL 关系型数据库 MySQL
MySQL入门到精通
MySQL入门到精通
|
24天前
|
关系型数据库 MySQL Shell
MySQL数据库一键安装脚本,适合任何版本
MySQL数据库一键安装脚本,适合任何版本
30 2