安装包准备
获取下载地址
选择对应的下载版本,如下图,右键RPM Bundle的Download
,复制下载链接地址
下载安装包
[hadoop@node3 installfile]$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar
查看安装包
[hadoop@node3 installfile]$ ls mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar
解压安装包
[hadoop@node3 installfile]$ mkdir ~/soft/mysql [hadoop@node3 installfile]$ tar -xvf mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar -C ~/soft/mysql
查看解压后的文件
[hadoop@node3 installfile]$ ll -h ~/soft/mysql/ total 865M -rw-r--r--. 1 hadoop hadoop 17M Sep 14 2022 mysql-community-client-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 2.6M Sep 14 2022 mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 647K Sep 14 2022 mysql-community-common-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 484M Sep 14 2022 mysql-community-debuginfo-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 1.9M Sep 14 2022 mysql-community-devel-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 4.1M Sep 14 2022 mysql-community-embedded-compat-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 2.2M Sep 14 2022 mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 1.6M Sep 14 2022 mysql-community-libs-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 670K Sep 14 2022 mysql-community-libs-compat-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 65M Sep 14 2022 mysql-community-server-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 25M Sep 14 2022 mysql-community-server-debug-8.0.31-1.el7.x86_64.rpm -rw-r--r--. 1 hadoop hadoop 263M Sep 14 2022 mysql-community-test-8.0.31-1.el7.x86_64.rpm
删除用不到的rpm包
rm -rf ~/soft/mysql/mysql-community-debuginfo-8.0.31-1.el7.x86_64.rpm rm -rf ~/soft/mysql/mysql-community-devel-8.0.31-1.el7.x86_64.rpm rm -rf ~/soft/mysql/mysql-community-embedded-compat-8.0.31-1.el7.x86_64.rpm rm -rf ~/soft/mysql/mysql-community-server-debug-8.0.31-1.el7.x86_64.rpm rm -rf ~/soft/mysql/mysql-community-test-8.0.31-1.el7.x86_64.rpm
删除下载的rpm-bundle tar包
[hadoop@node3 installfile]$ rm -rf mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar
安装
切换到解压目录,并创建安装脚本install_mysql.sh
[hadoop@node3 installfile]$ cd ~/soft/mysql/ [hadoop@node3 mysql]$ vim install_mysql.sh
脚本内容如下:
#!/bin/bash
set -x
[ "$(ls *.rpm | wc -l)" = "7" ] || exit 1
test -f mysql-community-client-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-common-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-libs-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-libs-compat-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-server-8.0.31-1.el7.x86_64.rpm || exit 1
# 卸载MySQL
sudo systemctl stop mysql mysqld 2>/dev/null
sudo rpm -qa | grep -i 'mysql\|mariadb' | xargs -n1 sudo rpm -e --nodeps 2>/dev/null
sudo rm -rf /var/lib/mysql /var/log/mysqld.log /usr/lib64/mysql /etc/my.cnf /usr/my.cnf
set -e
# 安装并启动MySQL
sudo yum install -y *.rpm >/dev/null 2>&1
sudo systemctl start mysqld
#更改密码级别并重启MySQL
sudo sed -i '/\[mysqld\]/avalidate_password.length=4\nvalidate_password.policy=0' /etc/my.cnf
sudo systemctl restart mysqld
# 更改MySQL配置
tpass=$(sudo cat /var/log/mysqld.log | grep "temporary password" | awk '{print $NF}')
cat << EOF | mysql -uroot -p"${tpass}" --connect-expired-password >/dev/null 2>&1
set password='000000';
update mysql.user set host='%' where user='root';
alter user 'root'@'%' identified with mysql_native_password by '000000';
flush privileges;
EOF
执行脚本
[hadoop@node3 mysql]$ sh install_mysql.sh
测试mysql
[hadoop@node3 mysql]$ mysql -uroot -p00000 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [hadoop@node3 mysql]$ mysql -uroot -p000000 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: 8.0.31 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> quit Bye [hadoop@node3 mysql]$
完成!enjoy it!