Linux环境Centos下安装Mysql详细教程

▶ 下载mysql安装包

1、创建/usr/local/mysql8目录,用于存放mysql8。

mkdir /usr/local/mysql8

cd /usr/local/mysql8

2、下载mysql安装包

wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm

▶ 安装mysql

1、执行命令安装mysql

yum -y install mysql80-community-release-el7-2.noarch.rpm

发生报错,报错内容如下:

Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
无法下载 repo 'appstream' 的元数据:无法准备内部镜像列表:镜像列表中没有 URL

2、执行以下命令从CentOS 8 迁移到CentOS Stream 8,解决上述问题。 

dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos

 3、迁移完成后,继续执行以下命令安装mysql。

yum -y install mysql80-community-release-el7-2.noarch.rpm

4、执行以下命令下载

yum -y install mysql-community-server

报错内容如下:

[root@localhost mysql8]# yum -y install mysql-community-server
MySQL 8.0 Community Server                      972 kB/s | 2.4 MB     00:02    
MySQL Connectors Community                       52 kB/s |  51 kB     00:00    
MySQL Tools Community                           380 kB/s | 711 kB     00:01    
All matches were filtered out by modular filtering for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server

5、针对步骤4出现"无法匹配"的问题,解决方式如下:

5.1、执行以下命令关闭centos8本地的mysql模块。

yum module disable mysql
执行结果:
[root@localhost mysql8]# yum module disable mysql
Last metadata expiration check: 0:00:52 ago on Wed 14 Sep 2022 11:28:18 AM CST.
Dependencies resolved.
================================================================================
 Package           Architecture     Version             Repository         Size
================================================================================
Disabling modules:
 mysql                                                                         

Transaction Summary
================================================================================

Is this ok [y/N]: y
Complete!

5.2、执行yum -y install mysql-community-server --nogpgcheck命令在禁止进行gpg check的情况下继续进行安装。 

yum -y install mysql-community-server --nogpgcheck

执行结果:

[root@localhost mysql8]# yum -y install mysql-community-server --nogpgcheck
Last metadata expiration check: 0:04:24 ago on Wed 14 Sep 2022 11:28:18 AM CST.
Dependencies resolved.
================================================================================
 Package                        Arch   Version          Repository         Size
================================================================================
Installing:
 mysql-community-server         x86_64 8.0.30-1.el7     mysql80-community  54 M
Installing dependencies:
 compat-openssl10               x86_64 1:1.0.2o-4.el8   appstream         1.1 M
 mysql-community-client         x86_64 8.0.30-1.el7     mysql80-community  14 M
 mysql-community-client-plugins x86_64 8.0.30-1.el7     mysql80-community 2.5 M
 mysql-community-common         x86_64 8.0.30-1.el7     mysql80-community 645 k
 mysql-community-icu-data-files x86_64 8.0.30-1.el7     mysql80-community 2.1 M
 mysql-community-libs           x86_64 8.0.30-1.el7     mysql80-community 1.5 M
 ncurses-compat-libs            x86_64 6.1-9.20180224.el8
                                                        baseos            328 k

Transaction Summary
================================================================================
Install  8 Packages

Total size: 76 M
Installed size: 351 M
Downloading Packages:
[SKIPPED] compat-openssl10-1.0.2o-4.el8.x86_64.rpm: Already downloaded         
[SKIPPED] ncurses-compat-libs-6.1-9.20180224.el8.x86_64.rpm: Already downloaded
[SKIPPED] mysql-community-client-8.0.30-1.el7.x86_64.rpm: Already downloaded   
[SKIPPED] mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm: Already downloaded
[SKIPPED] mysql-community-common-8.0.30-1.el7.x86_64.rpm: Already downloaded   
[SKIPPED] mysql-community-icu-data-files-8.0.30-1.el7.x86_64.rpm: Already downloaded
[SKIPPED] mysql-community-libs-8.0.30-1.el7.x86_64.rpm: Already downloaded     
[SKIPPED] mysql-community-server-8.0.30-1.el7.x86_64.rpm: Already downloaded   
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : compat-openssl10-1:1.0.2o-4.el8.x86_64                 1/8 
  Running scriptlet: compat-openssl10-1:1.0.2o-4.el8.x86_64                 1/8 
  Installing       : mysql-community-client-plugins-8.0.30-1.el7.x86_64     2/8 
  Installing       : mysql-community-common-8.0.30-1.el7.x86_64             3/8 
  Installing       : mysql-community-libs-8.0.30-1.el7.x86_64               4/8 
  Running scriptlet: mysql-community-libs-8.0.30-1.el7.x86_64               4/8 
  Installing       : mysql-community-icu-data-files-8.0.30-1.el7.x86_64     5/8 
  Installing       : ncurses-compat-libs-6.1-9.20180224.el8.x86_64          6/8 
  Installing       : mysql-community-client-8.0.30-1.el7.x86_64             7/8 
  Running scriptlet: mysql-community-server-8.0.30-1.el7.x86_64             8/8 
  Installing       : mysql-community-server-8.0.30-1.el7.x86_64             8/8 
  Running scriptlet: mysql-community-server-8.0.30-1.el7.x86_64             8/8 
  Verifying        : compat-openssl10-1:1.0.2o-4.el8.x86_64                 1/8 
  Verifying        : ncurses-compat-libs-6.1-9.20180224.el8.x86_64          2/8 
  Verifying        : mysql-community-client-8.0.30-1.el7.x86_64             3/8 
  Verifying        : mysql-community-client-plugins-8.0.30-1.el7.x86_64     4/8 
  Verifying        : mysql-community-common-8.0.30-1.el7.x86_64             5/8 
  Verifying        : mysql-community-icu-data-files-8.0.30-1.el7.x86_64     6/8 
  Verifying        : mysql-community-libs-8.0.30-1.el7.x86_64               7/8 
  Verifying        : mysql-community-server-8.0.30-1.el7.x86_64             8/8 

Installed:
  compat-openssl10-1:1.0.2o-4.el8.x86_64                                        
  mysql-community-client-8.0.30-1.el7.x86_64                                    
  mysql-community-client-plugins-8.0.30-1.el7.x86_64                            
  mysql-community-common-8.0.30-1.el7.x86_64                                    
  mysql-community-icu-data-files-8.0.30-1.el7.x86_64                            
  mysql-community-libs-8.0.30-1.el7.x86_64                                      
  mysql-community-server-8.0.30-1.el7.x86_64                                    
  ncurses-compat-libs-6.1-9.20180224.el8.x86_64                                 

Complete!

▶ 启动mysql 

1、执行命令启动数据库。

systemctl start  mysqld.service

2、执行命令查看当前登录密码。

grep "password" /var/log/mysqld.log

执行结果:

[root@localhost ~]# grep "password" /var/log/mysqld.log
2022-09-14T03:33:50.871635Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hfi-u/uXd5ma

3、执行命令登录mysql数据库。其中-u代表指定用户,-p代表指定密码。 

mysql -u root -p 

 执行结果:

[root@localhost ~]# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.30

Copyright (c) 2000, 2022, 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、执行命令查看mysql状态。这里观察到,mysqld.service状态为active。 

systemctl status mysqld.service

 执行结果:

[root@localhost ~]# systemctl status mysqld.service 
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: >
   Active: active (running) since Wed 2022-09-14 11:33:54 CST; 2h 53min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 36779 (mysqld)
   Status: "Server is operational"
    Tasks: 39 (limit: 4636)
   Memory: 49.3M
   CGroup: /system.slice/mysqld.service
           └─36779 /usr/sbin/mysqld
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西米先生「软件工程师」

您的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值