Linux上MySQL的四种安装方式

Linux上MySQL有四种安装方式

  1. 仓库安装

  1. 本地安装包安装

  1. docker容器安装

  1. 二进制源码安装

  1. 仓库安装

配置yum源,在/etc/yum.repos.d/目录下创建仓库文件

[base]
name=CentOS-8.5.2111 - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
        http://mirrors.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that may be useful
[extras]
name=CentOS-8.5.2111 - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/
        http://mirrors.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-8.5.2111 - Plus - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/centosplus/$basearch/os/
        http://mirrors.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/
gpgcheck=0
enabled=0

yum makecache服务器的包信息下载到本地电脑缓存起来

[root@KATANA ~]# yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
17 文件已删除
[root@KATANA ~]# yum makecache 
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                                                                           158 kB/s | 8.4 MB     00:54    
CentOS-8.5.2111 - Base - mirrors.aliyun.com                                                                                225 kB/s | 4.6 MB     00:20    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                                                              4.5 kB/s |  10 kB     00:02    
元数据缓存已建立。
[root@KATANA ~]# 

安装MySQL

yum install mysql-server -y

成功进入数据库

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2021, 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.

root@localhost [(none)]>

  1. 本地安装包安装

从官网下载安装包

[root@KATANA mysql]# wget  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar
--2023-02-14 16:52:17--  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 23.194.211.12
正在连接 cdn.mysql.com (cdn.mysql.com)|23.194.211.12|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:849367040 (810M) [application/x-tar]
正在保存至: “mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar”

mysql-8.0.32-1.el9.x86_64.rpm-bundle.t 100%[===========================================================================>] 810.02M  12.5MB/s  用时 67s     

2023-02-14 16:53:24 (12.1 MB/s) - 已保存 “mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar” [849367040/849367040])

[root@KATANA mysql]# ll
总用量 829460
-rw-r--r--. 1 root root 849367040 12月 17 20:38 mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar
[root@KATANA mysql]# 

解包tar包

[root@KATANA 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
[root@KATANA mysql]# 

安装MySQL

[root@KATANA 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

  1. docker容器安装

拉取mysql-server镜像

[root@katana ~]# docker pull mysql/mysql-server
Using default tag: latest
latest: Pulling from mysql/mysql-server
6a4a3ef82cdc: Pull complete 
5518b09b1089: Pull complete 
b6b576315b62: Pull complete 
349b52643cc3: Pull complete 
abe8d2406c31: Pull complete 
c7668948e14a: Pull complete 
c7e93886e496: Pull complete 
Digest: sha256:d6c8301b7834c5b9c2b733b10b7e630f441af7bc917c74dba379f24eeeb6a313
Status: Downloaded newer image for mysql/mysql-server:latest
docker.io/mysql/mysql-server:latest
[root@katana ~]# 

启动mysql容器

[root@katana ~]# docker run --name=mysql-server1 -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123123 -d mysql/mysql-server
0457a8f0b1d2d12e34eb8dbdc9bc3c86fe78102d116a1f6512f41f9a14f5a49b

进入容器启动mysql

[root@katana ~]# docker exec -it mysql-server1 bash
bash-4.4# mysql -uroot -p123123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 MySQL Community Server - GPL

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> 

4.二进制源码安装

官网下载二进制源码包

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

添加mysql用户和组

[root@KATANA ~]# groupadd mysql
[root@KATANA ~]# useradd -r -g mysql -s /bin/false mysql

解压安装

[root@KATANA ~]# tar xvf mysql-boost-8.0.32.tar.gz
[root@KATANA mysql-8.0.32]# yum install gcc gcc-c++ cmake -y
[root@KATANA ~]# 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@KATANA ~]# 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@KATANA ~]# cd mysql-8.0.32/
[root@KATANA mysql-8.0.32]# mkdir bld
[root@KATANA mysql-8.0.32]# cd bld
[root@KATANA bld]# cmake .. -DWITH_BOOST=../boost/boost_1_77_0/
[root@KATANA bld]# make    
[root@KATANA bld]# make install
[root@KATANA mysql]# cd /usr/local/mysql
[root@KATANA mysql]# mkdir mysql-files
[root@KATANA mysql]# chown mysql:mysql mysql-files
[root@KATANA mysql]# chmod 750 mysql-files
[root@KATANA mysql]# ./bin/mysqld --initialize --user=mysql

开启服务

[root@localhost ~]# systemctl start mysqld

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值