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安装结束。