redhat9安装mysql8.0版本--四种安装方式

目录

环境准备

仓库安装

安装仓库

下载数据库

本地安装

容器安装

源码安装


       MySQL数据库存在多种版本,不同的版本在不同的平台上(OS,也就是操作系统上)安装方式可能有所不同,因此安装时一定要参照官方文档进行安装。MySQL :: MySQL Documentation

环境准备

首先准备红帽9的系统

[root@192 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 9.1 (Plow)

配置源

建立本地光盘源

        BaseOS存储库:

           提供一套核心的底层操作系统功能,为基础软件安装库
        Appstream储存库:

             包括额外的用户空间应用程序、运行时语言和数据库,以支持不同的工作负载和用力。             AppStream中的内容有两种格式--RPM格式的和称为模块的RPM格式扩展。

[root@192 ~]# mkdir /mnt/cdrom          #创建要挂载的目录

[root@192 ~]# mount /dev/sr0 /mnt/cdrom          # 进行挂载,临时挂载。永久挂载编辑/etc/fstab文件

[root@192 ~]# mount -a


# 进入/etc/yum.repo.d写本地源

[root@192 ~]# vim /etc/yum.repos.d/rhel9.repo 

[rhel9-baseos]
name=rhel9-baseos
baseurl=file:///mnt/cdrom/BaseOS
gpgcheck=0

[rhel9-appstream]
name=rhel9-appstream
baseurl=file:///mnt/cdrom/AppStream
gpgcheck=0

 验证:

[root@192 yum.repos.d]# yum repolist

配置互联网源:

我们使用的阿里源

进入阿里开源镜像站 :        阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区

[root@192 ~]# vim /etc/yum.repos.d/aliyun_yum.repo 

[ali_baseos]
name=ali_baseos
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/
gpgcheck=0

[ali_appstream]
name=ali_appstream
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/os/
gpgcheck=0

进行验证:

[root@192 ~]# yum repolist

仓库安装

安装仓库

官网下载安装

首先去官网下载镜像(进入官网       MySQL

然后点击DOWNLOADS,进入下载页面

        

选择社区下载

 选择mysql的yum仓库

选择合适的版本下载,这里主要测试红帽9安装mysql8版本,我们选择第一个。

没有注册过的同学注意,选择,不注册,仅仅开始下载。

 然后将下载的rpm包传送到linux系统中

我们借用了lrzsz工具,将想传输的文件用鼠标拖拉到Linux相应的目录中。

[root@192 mysql]# mkdir /root/mysql/

[root@192 mysql]# cd /root/mysql/
[root@192 mysql]# ls -l
总用量 12
-rw-r--r--. 1 root root 10534  2月  8 13:41 mysql80-community-release-el9-1.noarch.rpm
 

# 将文件进行安装,使用rpm命令

[root@192 mysql]# rpm -ivh mysql80-community-release-el9-1.noarch.rpm

[root@192 mysql]# ls -l /etc/yum.repos.d/

或者使用

[root@localhost ~]# rpm -ivh  https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm

下载数据库

[root@192 ~]# yum install -y mysql-server

[root@192 ~]# rpm -qa | grep mysql

 [root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log

 上图红框框为初始密码

登录

mysql -uroot -p
#登录之后必须先修改用户密码,默认密码策略要求密码至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin123!';  # 更改密码

 

本地安装

官网下载

 

 

 更具自己需要的版本选择相应的包

将下载好的包传入linux系统的相应的目录中

或者

[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

 安装所有的包

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

容器安装

[root@localhost ~]# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

[root@localhost ~]# dnf install -y yum-utils device-mapper-persistent-data lvm2

[root@localhost ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
[root@localhost ~]# dnf install docker-ce --allowerasing -y
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl status docker
[root@localhost ~]# docker version
[root@localhost ~]# docker run hello-world
[root@localhost ~]# docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysql
[root@localhost ~]# docker ps
[root@localhost ~]# docker exec -it mysqltest /bin/bash
bash-4.4# mysql -uroot -p  
Enter password: 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye
bash-4.4# exit
exit

源码安装

## 参考官方文档 https://dev.mysql.com/doc/refman/8.0/en/installing-source-distribution.html

[root@localhost ~]# wget  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.32.tar.gz

#添加用户和组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql
#开始源码安装
[root@localhost ~]# tar xvf mysql-boost-8.0.32.tar.gz
[root@localhost mysql-8.0.32]# yum install gcc gcc-c++ cmake -y
[root@localhost bld]# 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
[root@localhost ~]# cd mysql-8.0.32/
[root@localhost mysql-8.0.32]# mkdir bld
[root@localhost mysql-8.0.32]# cd bld
[root@localhost bld]# cmake .. -DWITH_BOOST=../boost/boost_1_77_0/
[root@localhost bld]# make    ########该过程很久,请耐心等待
[root@localhost bld]# make install
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# mkdir mysql-files
[root@localhost mysql]# chown mysql:mysql mysql-files
[root@localhost mysql]# chmod 750 mysql-files
[root@localhost mysql]# bin/mysqld --initialize --user=mysql
[root@localhost mysql]# bin/mysql_ssl_rsa_setup
[root@localhost mysql]# bin/mysqld_safe --user=mysql &
[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
[root@localhost mysql]# ./bin/mysql -uroot -p
Enter password: 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin123!';
mysql> show databases;
mysql> exit

#停止mysql服务
[root@localhost mysql]# ./bin/mysqladmin -uroot -pAdmin123! shutdown

# Next command is optional
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql.server
[root@localhost mysql]# systemctl daemon-reload
[root@localhost mysql]# systemctl start mysql

mysql初始安全化设置

[root@192 ~]# mysql_secure_installation 

[root@192 ~]# mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root:  # 输入密码
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 

# 是否改变root用户密码
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.


By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

# 是否删除匿名用户

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

# 是否禁止root用户远程登录

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

# 是否删除测试数据库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

# 是否重新加载权限表

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
 

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值