方法1
[root@server ~]# rpm -ivh https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm
[root@server ~]# ls -l /etc/yum.repos.d/
total 20
-rw-r--r--. 1 root root 323 Sep 11 19:20 CentOS-9-Stream.repo
-rw-r--r--. 1 root root 951 Jul 6 2022 mysql-community-debuginfo.repo
-rw-r--r--. 1 root root 827 Jul 6 2022 mysql-community.repo
-rw-r--r--. 1 root root 871 Jul 6 2022 mysql-community-source.repo
-rw-r--r--. 1 root root 358 Sep 11 19:21 redhat.repo
[root@server ~]# dnf install mysql-server
[root@server ~]# systemctl start mysqld
[root@server ~]# systemctl status mysqld
[root@server ~]# grep 'temporary password' /var/log/mysqld.log
2023-09-18T06:47:39.304575Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ?ke6,8s1OU5-
[root@server ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.34
Copyright (c) 2000, 2023, 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>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wyxbuke00.';
方法2:Docker安装
[root@server ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@server ~]# ls -l /etc/yum.repos.d/
total 24
-rw-r--r--. 1 root root 323 Sep 11 19:20 CentOS-9-Stream.repo
-rw-r--r--. 1 root root 2081 Sep 18 15:24 docker-ce.repo
[root@server ~]# yum install docker-ce -y
[root@server ~]# systemctl restart docker
[root@server ~]# docher search centos
[root@server ~]# docker run --name mysql-test -e MYSQL_ROOT_PASSWORD -d mysql
[root@server ~]# docker run --name mysql-test3 -d -it -e MYSQL_ROOT_PASSWORD=123456 mysql
[root@server ~]# docker exec -it mysql-test3 /bin/bash