在RockyLinux9.5系统上使用yum方式在线安装MySQL8

echo "删除系统默认或之前可能安装的其他版本的 mysql"

for i in $(rpm -qa|grep mysql);do rpm -e $i --nodeps;done
rm -rf /var/lib/mysql && rm -rf /etc/my.cnf

echo "安装Mysql8.0 的yum资源库"
yum -y localinstall https://repo.mysql.com/mysql84-community-release-el9.rpm

# 注意:默认直接yum安装是8.x的最新版本:8.4。若是想安装8.0版本的,需要修改repo文件
vim mysql-community.repo

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-innovation-community]
name=MySQL Innovation Release Community Server
baseurl=http://repo.mysql.com/yum/mysql-innovation-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

[mysql-8.4-lts-community]
name=MySQL 8.4 LTS Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.4-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-innovation-community]
name=MySQL Tools Innovation Community
baseurl=http://repo.mysql.com/yum/mysql-tools-innovation-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

[mysql-tools-8.4-lts-community]
name=MySQL Tools 8.4 LTS Community
baseurl=http://repo.mysql.com/yum/mysql-tools-8.4-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023

[mysql-cluster-8.0-community]
name=MySQL Cluster 8.0 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-8.0-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-innovation-community]
name=MySQL Cluster Innovation Release Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-innovation-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

[mysql-cluster-8.4-lts-community]
name=MySQL Cluster 8.4 LTS Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-8.4-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023


yum makecache

yum -y install mysql-community-server  # 这个时候安装的版本是8.0.42的

echo "安装Mysql8.0.29"
yum -y install mysql-community-server

echo "启动之前修改配置文件,增加上不区分大小写的参数"

rm -rf /etc/my.cnf

cat >> /etc/my.cnf << EOF
[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4' # 注意,是英文状态下的单引号,不是中文状态下的
default_authentication_plugin=mysql_native_password

default-storage-engine=INNODB
lower_case_table_names=1
skip-name-resolve
max_connections=500

EOF

echo "启动MySQL服务器和MySQL的自动启动"
systemctl start mysqld.service
systemctl enable mysqld.service

echo "查看默认密码"
grep 'temporary password' /var/log/mysqld.log

echo "使用默认密码初次登录后, 必须要重置密码"
posted @ 2025-06-06 14:01  哈喽哈喽111111  阅读(200)  评论(0)    收藏  举报