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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 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安装结束。


相关文章
|
1月前
|
SQL 关系型数据库 MySQL
网安入门之MySQL后端基础
《网安入门之MySQL后端基础》简介: 本文介绍了数据库及MySQL的基础知识,涵盖数据库的概念、结构与操作。数据库是组织化存储数据的集合,通过表、列、行等结构实现高效管理。MySQL作为开源的关系型数据库管理系统,广泛应用于Web开发。文中详细讲解了MySQL的基本操作,如增(INSERT)、删(DELETE)、改(UPDATE)、查(SELECT)等语句的使用方法,并介绍了数据库事务的ACID特性。此外,还探讨了SQL注入攻击的风险及防范措施,强调了预处理语句的重要性。最后,简述了PHP中mysqli扩展的使用方法,包括连接数据库、执行查询和关闭连接等步骤。
|
25天前
|
关系型数据库 MySQL 数据库连接
数据库连接工具连接mysql提示:“Host ‘172.23.0.1‘ is not allowed to connect to this MySQL server“
docker-compose部署mysql8服务后,连接时提示不允许连接问题解决
|
12天前
|
关系型数据库 MySQL 数据库
Docker Compose V2 安装常用数据库MySQL+Mongo
以上内容涵盖了使用 Docker Compose 安装和管理 MySQL 和 MongoDB 的详细步骤,希望对您有所帮助。
91 42
|
3天前
|
关系型数据库 MySQL 网络安全
如何排查和解决PHP连接数据库MYSQL失败写锁的问题
通过本文的介绍,您可以系统地了解如何排查和解决PHP连接MySQL数据库失败及写锁问题。通过检查配置、确保服务启动、调整防火墙设置和用户权限,以及识别和解决长时间运行的事务和死锁问题,可以有效地保障应用的稳定运行。
44 25
|
1月前
|
安全 关系型数据库 MySQL
CentOS7仅安装部署MySQL80客户端
通过上述步骤,你可以在CentOS 7上成功安装并配置MySQL 8.0客户端。这个过程确保你能够使用MySQL客户端工具连接和管理远程的MySQL数据库,而不需要在本地安装MySQL服务器。定期更新MySQL客户端可以确保你使用的是最新的功能和安全修复。
170 16
|
1月前
|
传感器 安全 物联网
时序数据库TDengine + MQTT :车联网时序数据库如何高效接入
现代新能源汽车配备大量传感器,产生海量数据需上报至车联网平台。TDengine作为时序大数据平台,支持MQTT协议,可轻松实现车辆状态、位置及用户行为数据的实时采集与分析,提升驾驶体验和安全保障。通过简单的Web界面配置,无需编写代码,即可完成从MQTT到TDengine的数据接入。整个过程包括注册TDengine Cloud、创建数据库、安装代理插件、新增数据源、配置解析规则等步骤,快速实现数据同步。
53 2
|
30天前
|
缓存 关系型数据库 MySQL
【深入了解MySQL】优化查询性能与数据库设计的深度总结
本文详细介绍了MySQL查询优化和数据库设计技巧,涵盖基础优化、高级技巧及性能监控。
256 0
|
4月前
|
消息中间件 JSON Java
开发者如何使用轻量消息队列MNS
【10月更文挑战第19天】开发者如何使用轻量消息队列MNS
316 11
|
4月前
|
消息中间件 安全 Java
云消息队列RabbitMQ实践解决方案评测
一文带你详细了解云消息队列RabbitMQ实践的解决方案优与劣
129 10
|
3月前
|
消息中间件 存储 Kafka
MQ 消息队列核心原理,12 条最全面总结!
本文总结了消息队列的12个核心原理,涵盖消息顺序性、ACK机制、持久化及高可用性等内容。关注【mikechen的互联网架构】,10年+BAT架构经验倾囊相授。