1.仓库安装
1.1查看版本和安装mysql包
[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 9.1 (Plow)
[root@localhost ~]# rpm -ivh https://repo.mysql.com/mysql80-community-release-el9-1.noarch.rpm
1.2装包
[root@localhost ~]# dnf install mysql-server -y
1.3查看所装的包
[root@localhost ~]# rpm -qa | grep mysql
mysql80-community-release-el9-1.noarch
mysql-community-common-8.0.32-1.el9.x86_64
mysql-community-client-plugins-8.0.32-1.el9.x86_64
mysql-community-libs-8.0.32-1.el9.x86_64
mysql-community-client-8.0.32-1.el9.x86_64
mysql-community-icu-data-files-8.0.32-1.el9.x86_64
mysql-community-server-8.0.32-1.el9.x86_64
1.4运行
[root@localhost ~]# systemctl start mysqld
1.5查看初始密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
1.6登录数据库,修改密码
[root@localhost ~]# mysql -uroot -p'h#:FoU;YP5an'
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin123!';
1.7删除数据库
[root@localhost ~]# dnf remove mysql-server -y
[root@localhost ~]# rpm -qa | grep mysql
mysql80-community-release-el9-1.noarch
[root@localhost ~]# dnf remove mysql80-community-release -y
[root@localhost ~]# rm -rf /var/lib/mysql/ /var/log/mysqld.log
2.本地安装
2.1新建目录
[root@localhost ~]# mkdir mysql
2.2下载mysql的rpm包,解压包
root@localhost ~]# cd mysql/
[root@localhost mysql]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar
[root@localhost mysql]# tar xvf mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar
mysql-community-client-8.0.32-1.el9.x86_64.rpm
mysql-community-client-debuginfo-8.0.32-1.el9.x86_64.rpm
mysql-community-client-plugins-8.0.32-1.el9.x86_64.rpm
mysql-community-client-plugins-debuginfo-8.0.32-1.el9.x86_64.rpm
mysql-community-common-8.0.32-1.el9.x86_64.rpm
mysql-community-debuginfo-8.0.32-1.el9.x86_64.rpm
mysql-community-debugsource-8.0.32-1.el9.x86_64.rpm
mysql-community-devel-8.0.32-1.el9.x86_64.rpm
mysql-community-icu-data-files-8.0.32-1.el9.x86_64.rpm
mysql-community-libs-8.0.32-1.el9.x86_64.rpm
mysql-community-libs-debuginfo-8.0.32-1.el9.x86_64.rpm
mysql-community-server-8.0.32-1.el9.x86_64.rpm
mysql-community-server-debug-8.0.32-1.el9.x86_64.rpm
mysql-community-server-debug-debuginfo-8.0.32-1.el9.x86_64.rpm
mysql-community-server-debuginfo-8.0.32-1.el9.x86_64.rpm
mysql-community-test-8.0.32-1.el9.x86_64.rpm
mysql-community-test-debuginfo-8.0.32-1.el9.x86_64.rpm
2.3安装所需要的依赖包
[root@localhost mysql]# dnf localinstall mysql-community-server-8.0.32-1.el9.x86_64.rpm \
> mysql-community-client-8.0.32-1.el9.x86_64.rpm \
> mysql-community-common-8.0.32-1.el9.x86_64.rpm \
> mysql-community-icu-data-files-8.0.32-1.el9.x86_64.rpm \
> mysql-community-client-plugins-8.0.32-1.el9.x86_64.rpm \
> mysql-community-libs-8.0.32-1.el9.x86_64.rpm
2.4启动服务
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl status mysqld
2.5查看密码,登录数据库
[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
2023-02-14T18:18:22.274892Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g;,lsoeU7qgY
[root@localhost mysql]# mysql -uroot -pg;,lsoeU7qgY
3.容器安装
3.1 安装需要的依赖包
[root@localhost ~]# dnf install -y yum-utils device-mapper-persistent-data lvm2
3.2添加阿里云的容器仓库
[root@localhost ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3.3在下载docker时修改网站为阿里云网站
[root@localhost ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
3.4安装docker-ce
[root@localhost ~]# dnf install docker-ce --allowerasing -y
3.5启动容器
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl status docker
3.6测试容器
[root@localhost ~]# docker run hello-world
3.7运行mysqltest容器
[root@localhost ~]# docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysql
3.8进入
[root@localhost ~]# docker exec -it mysqltest /bin/bash
bash-4.4# mysql -uroot -p123321
4.源码安装
4.1添加用户和组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql
4.2创建目录
cd mysql-source/
4.3开始源码安装,下载源码包
[root@localhost ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.32.tar.gz
4.4解压包
[root@localhost ~]# tar xvf mysql-boost-8.0.32.tar.gz
4.5安装编译器所需要的东西
[root@localhost mysql-source]# cd mysql-8.0.32/
[root@localhost mysql-8.0.32]# yum install gcc gcc-c++ cmake -y
4.6安装编译时所需要的库
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
[root@localhost bld]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/CRB/x86_64/os/Packages/libtirpc-devel-1.3.3-0.el9.x86_64.rpm
4.7创建目录
[root@localhost mysql-8.0.32]# mkdir bld
[root@localhost mysql-8.0.32]# cd bld
4.8起服务,编译
[root@localhost bld]# cmake .. -DWITH_BOOST=../boost/boost_1_77_0/
[root@localhost bld]# make ########该过程很久,请耐心等待
[root@localhost bld]# make install
4.9 创建目录并修改所属者和所属组
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# mkdir mysql-files
[root@localhost mysql]# chown mysql:mysql mysql-files
4.10修改权限
[root@localhost mysql]# chmod 750 mysql-files
4.11初始化数据库
[root@localhost mysql]# bin/mysqld --initialize --user=mysql
4.12开启支持ssl加密
[root@localhost mysql]# bin/mysql_ssl_rsa_setup
4.13启动mysql进程
[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin123!';
4.14停止服务
[root@localhost mysql]# ./bin/mysqladmin -uroot -pAdmin123! shutdown