MySQL安装

  1. 仓库安装

下载:

[root@192 ~]# rpm -ivh  https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm
获取https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql80-community-release-el9-1  ################################# [100%]
   

安装MySQL服务器

[root@192 ~]# dnf install mysql-server -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

上次元数据过期检查:0:03:00 前,执行于 2023年02月13日 星期一 10时19分50秒。
依赖关系解决。
==========================================================================================================================
 软件包                                       架构                 版本                        仓库                       
==========================================================================================================================
安装:
 mysql-community-server                       x86_64               8.0.32-1.el9                mysql80-community          
安装依赖关系:
 mysql-community-client                       x86_64               8.0.32-1.el9                mysql80-community          
 mysql-community-client-plugins               x86_64               8.0.32-1.el9                mysql80-community          
 mysql-community-common                       x86_64               8.0.32-1.el9                mysql80-community          
 mysql-community-icu-data-files               x86_64               8.0.32-1.el9                mysql80-community          
 mysql-community-libs                         x86_64               8.0.32-1.el9                mysql80-community          

事务概要
==========================================================================================================================
安装  6 软件包

总下载:59 M
安装大小:335 M
下载软件包:
(1/6): mysql-community-common-8.0.32-1.el9.x86_64.rpm                                                774 kB/s | 544 kB    
(2/6): mysql-community-client-plugins-8.0.32-1.el9.x86_64.rpm                                        1.5 MB/s | 1.4 MB    
(3/6): mysql-community-icu-data-files-8.0.32-1.el9.x86_64.rpm                                        6.0 MB/s | 2.2 MB    
(4/6): mysql-community-libs-8.0.32-1.el9.x86_64.rpm                                                  7.0 MB/s | 1.5 MB    
(5/6): mysql-community-client-8.0.32-1.el9.x86_64.rpm                                                3.3 MB/s | 3.9 MB    
(6/6): mysql-community-server-8.0.32-1.el9.x86_64.rpm                                                 25 MB/s |  49 MB    
--------------------------------------------------------------------------------------------------------------------------
总计                                                                                                  19 MB/s |  59 MB    
MySQL 8.0 Community Server                                                                           3.0 MB/s | 3.1 kB    
导入 GPG 公钥 0x3A79BD29:
 Userid: "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 指纹: 859B E8D7 C586 F538 430B 19C2 467B 942D 3A79 BD29
 来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                               
  安装    : 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-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                                                                    
  安装    : mysql-community-server-8.0.32-1.el9.x86_64                                                                    
  运行脚本: mysql-community-server-8.0.32-1.el9.x86_64                                                                    
  验证    : mysql-community-client-8.0.32-1.el9.x86_64                                                                    
  验证    : mysql-community-client-plugins-8.0.32-1.el9.x86_64                                                            
  验证    : mysql-community-common-8.0.32-1.el9.x86_64                                                                    
  验证    : mysql-community-icu-data-files-8.0.32-1.el9.x86_64                                                            
  验证    : mysql-community-libs-8.0.32-1.el9.x86_64                                                                      
  验证    : mysql-community-server-8.0.32-1.el9.x86_64                                                                    
已更新安装的产品。

已安装:
  mysql-community-client-8.0.32-1.el9.x86_64                    mysql-community-client-plugins-8.0.32-1.el9.x86_64        
  mysql-community-common-8.0.32-1.el9.x86_64                    mysql-community-icu-data-files-8.0.32-1.el9.x86_64        
  mysql-community-libs-8.0.32-1.el9.x86_64                      mysql-community-server-8.0.32-1.el9.x86_64                

完毕!

启动MySQL并修改密码

[root@192 ~]# systemctl start mysqld
[root@192 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
     Active: active (running) since Mon 2023-02-13 10:24:41 CST; 23s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 36459 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
   Main PID: 36529 (mysqld)
     Status: "Server is operational"
      Tasks: 39 (limit: 31008)
     Memory: 475.4M
        CPU: 3.633s
     CGroup: /system.slice/mysqld.service
             └─36529 /usr/sbin/mysqld

2月 13 10:24:36 192.168.239.128 systemd[1]: Starting MySQL Server...
2月 13 10:24:41 192.168.239.128 systemd[1]: Started MySQL Server.
[root@192 ~]# grep password /var/log/mysqld.log
2023-02-13T02:24:39.344390Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Xtvh7+-4f
[root@192 ~]# mysql -u root -p'Xtvh7+-4fi0.'
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 10
Server version: 8.0.32

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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin123!';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye
  1. 本地安装

新建一个MySQL目录

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

新建一个MySQL目录

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

下载所需要的包并解包一下,安装依赖包

[root@192 mysql]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar  #下载
[root@192 mysql]# tar xf mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar #解包
[root@192 mysql]# rpm -ivh 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

  1. 容器安装

安装容器所需依赖包

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

添加仓库,并启动

[root@192 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@192 ~]# systemctl start docker
[root@192 ~]# systemctl status docker
[root@192 ~]# docker version
[root@192 ~]# docker run hello-world
[root@192 ~]# docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysql
[root@192 ~]# docker ps
[root@192 ~]# docker exec -it mysqltest /bin/bash

其余操作同1

  1. 源码安装:

下载源码包

[root@192 ~]# wget  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.32.tar.gz
--2023-02-12 18:26:30--  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.32.tar.gz
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 2.19.84.217
正在连接 cdn.mysql.com (cdn.mysql.com)|2.19.84.217|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:436207624 (416M) [application/x-tar-gz]
正在保存至: “mysql-boost-8.0.32.tar.gz.1”

mysql-boost-8.0.32.tar.gz.1   100%[=================================================>] 416.00M  7.60MB/s  用时 62s

2023-02-12 18:28:34 (6.76 MB/s) - 已保存 “mysql-boost-8.0.32.tar.gz.1” [436207624/436207624])

添加用户和组

[root@192 ~]# groupadd mysql
groupadd:“mysql”组已存在
[root@192 ~]# useradd -r -g mysql -s /bin/false mysql
useradd:用户“mysql”已存在

源码安装

[root@192 ~]# tar xvf mysql-boost-8.0.32.tar.gz
[root@192 ~]# yum install gcc gcc-c++ cmake -y
[root@192 ~]# 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@192 ~]# 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@192 ~]# cd mysql-8.0.32/
#新建一个目录
[root@192 mysql-8.0.32]# mkdir bld
[root@192 mysql-8.0.32]# cd bld
[root@192 bld]# cmake .. -DWITH_BOOST=../boost/boost_1_77_0/   #指定路径
#如果不清楚的话可以先查看:ls../boost
[root@192 bld]# make  #时间有点长!
[root@192 bld]# make install

做一下初始化配置

[root@192 bld]# cd /usr/local/mysql/
[root@192 mysql]# mkdir mysql-files
[root@192 mysql]# chown mysql:mysql mysql-files
[root@192 mysql]# chmod 750 mysql-files
[root@192 mysql]# ./bin/mysqld --initialize --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;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值