一,仓库安装
1,使用rpm命令从指定的网址装包
[root@localhost yum.repos.d]# rpm -ivh https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm

2,查看已经安装的仓库id和仓库名称,会发现多了以下几个仓库
MySQL Connectors Community; MySQL Tools Community ;MySQL 8.0 Community Server;
[root@localhost yum.repos.d]# yum repolist

3,安装mysql软件
[root@wangjingjing yum.repos.d]# dnf install mysql-server -y

4,运行mysql软件
[root@localhost yum.repos.d]# systemctl start mysqld
5,查看mysqld服务的状态
[root@wangjingjing yum.repos.d]# systemctl status mysqld
6,在/var/log/mysqld.log目录下面查看数据库root的临时密码
[root@localhost yum.repos.d]# grep 'temporary password'/var/log/mysqld.log
7,使用临时密码登录数据库(密码和-p之间不能有空格)
[root@localhost yum.repos.d]# mysql -uroot -p' 9tJZ4JPtVa,)'
8,查看数据库
mysql> show databases;

二,本地安装
1,新建一个mysql目录,并切换到mydql目录下
[root@localhost yum.repos.d]# mkdir mysql[root@localhost yum.repos.d]# cd mysql
2,下载rpm包
[root@localhost mysql]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32

3,下载完成后是一个tar包,需要解包
[root@localhost mysql]# tar xf mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar
4,解包后会生成许多rpm包
[root@localhost mysql]# ll

5,安装mysql时会用到一些依赖包;安装依赖包(包之间有依赖,一起安装)
[root@localhost mysql]# rpm -ivh mysql-community-server-8.0.32-1.el9.x86_64.rpm mysql-com
6,启动mysqld服务
[root@localhost mysql]# systemctl start mysqld

7,查看服务状态
[root@localhost mysql]# systemctl status mysqld

8,查看数据库
mysql> show databases;

三,容器安装
1,如果之前安装过容器相关的包;卸载已有的包
[root@localhost mysql]# rm -rf /var/lib/mysql /var/log/mysqld.log
[root@localhost mysql]# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2,装容器所需要的依赖包
[root@localhost mysql]# dnf install -y yum-utils device-mapper-persistent-data lvm2
3,需要写容器的仓库;添加阿里云的仓库
[root@localhost mysql]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4,查看目录/etc/yum.repos.d;会发现多了一个docker-ce.repo
[root@localhost mysql]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# ll

5,查看已经安装的仓库id和仓库名称,会发现多了1个仓库
[root@localhost yum.repos.d]# yum repolist
6,修改下载docker的网站,改为阿里云的(国内的比较快)
[root@localhost yum.repos.d]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+'
7,安装docker--ce时需要替换冲突软件包
[root@localhost yum.repos.d]# dnf install docker-ce --allowerasing -y
8,启动docker服务
[root@localhost yum.repos.d]# systemctl start docker
9,查看docker服务状态
[root@localhost yum.repos.d]# systemctl status docker
10,测试能否正常使用
[root@localhost yum.repos.d]# docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysql
11,进到容器里面操作数据库
[root@localhost yum.repos.d]# docker exec -it mysqltest /bin/bashbash-4.4# mysql -uroot -p123456
12,查看数据库
mysql> show databases;
四,源码安装
1,下载源码包
[root@localhost yum.repos.d]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.32.tar.gz
--2023-02-10 09:14:15-- https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.32.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.36.48.238
Connecting to cdn.mysql.com (cdn.mysql.com)|23.36.48.238|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 436207624 (416M) [application/x-tar-gz]
Saving to: ‘mysql-boost-8.0.32.tar.gz.1’
mysql-boost-8.0.32.tar.gz.1 100%[===================================================>] 416.00M 5.33MB/s in 74s
2023-02-10 09:15:30 (5.63 MB/s) - ‘mysql-boost-8.0.32.tar.gz.1’ saved [436207624/436207624]
2,添加用户和组:
[root@localhost yum.repos.d]# groupadd mysql
groupadd: group 'mysql' already exists
[root@localhost yum.repos.d]# useradd -r -g mysql -s /bin/false mysql
useradd: user 'mysql' already exists
[root@localhost yum.repos.d]#
3,解压包:
[root@localhost mysql-source]# tar xvf mysql-boost-8.0.32.tar.gz.1
4,解压完成后会生成一堆文件在mysql-8.0.32目录下:
[root@localhost mysql-source]# ll
total 425992
drwxr-xr-x. 32 7161 31415 4096 Dec 16 23:59 mysql-8.0.32
-rw-r--r--. 1 root root 436207624 Dec 16 23:01 mysql-boost-8.0.32.tar.gz.1
切换到目录mysql-8.0.32下,可以查看到源码包里面所有的东西
[root@localhost mysql-source]# cd mysql-8.0.32/
[root@localhost mysql-8.0.32]# ls
boost configure.cmake include libservices packaging share testclients
client Docs INSTALL LICENSE plugin sql unittest
cmake Doxyfile-ignored libbinlogevents man README sql-common utilities
CMakeLists.txt Doxyfile.in libbinlogstandalone mysql-test router storage vio
components doxygen_resources libchangestreams MYSQL_VERSION run_doxygen.cmake strings
config.h.cmake extra libmysql mysys scripts support-files
6,安装编译器
[root@localhost mysql-8.0.32]# yum install gcc gcc-c++ cmake -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
MySQL Tools Community 1.3 kB/s | 2.6 kB 00:01
baseos 2.7 MB/s | 2.7 kB 00:00
AppStream 3.1 MB/s | 3.2 kB 00:00
Dependencies resolved.
7,安装编译过程中可能需要的一些库:
[root@localhost mysql-8.0.32]# yum install cmake gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils openssl-devel ncurses-devel libtirpc rpcgen git -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
9,创建一个编译的目录:
[root@localhost mysql-8.0.32]# mkdir bld
10,编译(注意路径):
[root@localhost bld]# cmake .. -DWITH_BOOST=../boost/boost_1_77_0/
-- Running cmake version 3.20.2
-- Found Git: /usr/bin/git (found version "2.31.1")
11,编译
[root@localhost bld]# make

12,安装:把编译的文件拷贝到对应的系统下的目录
[root@localhost bld]# make install
13,切换到目录/usr/local/mysql下
[root@localhost bld]# cd /usr/local/mysql
14,创建目录 mysql-files 用来存储mysql的一些数据
[root@localhost mysql]# mkdir mysql-files
15,修改此目录的所属者与所属组以及此目录的权限,防止mysql读不到,
[root@localhost mysql]# chown mysql:mysql mysql-files[root@localhost mysql]# chmod 750 mysql-files
16,初始化数据库
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql
17,开启lsl的加密
[root@localhost mysql]# ./bin/mysql_ssl_rsa_setup
18,获取临时密码
[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
2023-02-07T13:07:17.842453Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: *2D):irrJ_!_
19,使用新密码登录
[root@localhost mysql]# mysql -uroot -p'Admin123!';
20,查看数据库
mysql> show databases;
