二、MySQL 安装部署
2.1 RPM包安装
2.1.1 yum在线安装
1、下载并安装MySQL官方的 Yum Repository
[root@node1 ~]# wget -c https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
2、添加 MySQL Yum Repository
[root@node1 ~]# yum localinstall mysql80-community-release-el7-5.noarch.rpm -y
3、选择安装发行版
前提: 安装yum-utils包
[root@node1 ~]# yum-config-manager --disable mysql80-community #禁用8.0
[root@node1 ~]# yum-config-manager --enable mysql57-community #启用5.7
验证
[root@node1 ~]# yum repolist enabled | grep -i ^mysql mysql-connectors-community/x86_64 MySQL Connectors Community 230 mysql-tools-community/x86_64 MySQL Tools Community 138 mysql57-community/x86_64 MySQL 5.7 Community Server 564
4、在线安装
[root@node1 ~]# yum install -y mysql-community-server
5、启动数据库
[root@node1 ~]# systemctl enable --now mysqld
6、登陆
[root@node1 ~]# tmp_pwd=`awk '/temporary password/ {print $NF}' /var/log/mysqld.log`
[root@node1 ~]# mysql -uroot -p$tmp_pwd
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.37 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
7、验证
#查看状态
[root@node1 ~]# systemctl status mysqld
#查看端口
[root@node1 ~]# netstat -lnpt | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 1823/mysqld
#查看进程
[root@node1 ~]# ps -ef | grep mysqld
mysql 1823 1 0 22:08 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 1856 1393 0 22:10 pts/0 00:00:00 grep --color=auto mysqld
2.1.2 rpm包离线安装
事先从官网下载RPM安装包,上传至服务器:
[root@node2 ~]# ls -l mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 root root 545894400 Mar 27 22:31 mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
解压查看:
[root@node2 ~]# tar xf mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
[root@node2 ~]# ls -l mysql-community-*
-rw-r--r-- 1 7155 31415 26670472 Dec 16 10:01 mysql-community-client-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 318884 Dec 16 10:01 mysql-community-common-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 4122424 Dec 16 10:01 mysql-community-devel-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 47760004 Dec 16 10:02 mysql-community-embedded-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 23316972 Dec 16 10:02 mysql-community-embedded-compat-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 132204460 Dec 16 10:02 mysql-community-embedded-devel-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2474780 Dec 16 10:02 mysql-community-libs-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 1264836 Dec 16 10:02 mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 182274360 Dec 16 10:02 mysql-community-server-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 7155