Linux安装mysql总结

1 查看是否已安装mysql,如果已安装先卸载

[work@lsdBKusFRn mysql]$ rpm -qa | grep mysql
mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64
mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64
mysql57-community-release-el7-10.noarch

可以看到之前有安装过mysql,先将其从系统卸载

[root@lsdBKusFRn ~]# yum remove mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64
Dependencies resolved.
========================================================================================================================================================================
 Package                                       Architecture              Version                                                    Repository                     Size
========================================================================================================================================================================
Removing:
 mysql-common                                  x86_64                    8.0.26-1.module_el8.4.0+915+de215114                       @AppStream                    460 k
Removing dependent packages:
 mysql                                         x86_64                    8.0.26-1.module_el8.4.0+915+de215114                       @AppStream                     63 M
Removing unused dependencies:
 mariadb-connector-c-config                    noarch                    3.1.11-2.el8_3                                             @AppStream                    497  

Transaction Summary
========================================================================================================================================================================
Remove  3 Packages

Freed space: 63 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                1/1 
  Erasing          : mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64                                                                                              1/3 
  Erasing          : mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64                                                                                       2/3 
  Erasing          : mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                                                                               3/3 
  Running scriptlet: mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                                                                               3/3 
  Verifying        : mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                                                                               1/3 
  Verifying        : mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64                                                                                              2/3 
  Verifying        : mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64                                                                                       3/3 

Removed:
  mariadb-connector-c-config-3.1.11-2.el8_3.noarch    mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64    mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64   

Complete!
[root@lsdBKusFRn ~]# yum remove mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64
No match for argument: mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64
No packages marked for removal.
Dependencies resolved.
Nothing to do.
Complete!
[root@lsdBKusFRn ~]# yum remove mysql57-community-release-el7-10.noarch
Dependencies resolved.
========================================================================================================================================================================
 Package                                             Architecture                     Version                             Repository                               Size
========================================================================================================================================================================
Removing:
 mysql57-community-release                           noarch                           el7-10                              @@commandline                            30 k

Transaction Summary
========================================================================================================================================================================
Remove  1 Package

Freed space: 30 k
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                1/1 
  Erasing          : mysql57-community-release-el7-10.noarch                                                                                                        1/1 
  Verifying        : mysql57-community-release-el7-10.noarch                                                                                                        1/1 

Removed:
  mysql57-community-release-el7-10.noarch                                                                                                                               

Complete!

执行完卸载命令,我们再确认一下是否已从系统卸载完成

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

没有任何输出,表示已经卸载完成

2 下载官方mysql安装包

按照需求从官网下载相应版本的mysql安装包

[root@lsdBKusFRn ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
--2022-05-28 18:12:48--  https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm [following]
--2022-05-28 18:12:49--  https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.58.116.230
Connecting to repo.mysql.com (repo.mysql.com)|23.58.116.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25680 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-11.noarch.rpm’

mysql57-community-release-el7-11.noarch.r 100%[=====================================================================================>]  25.08K   130KB/s    in 0.2s    

2022-05-28 18:12:50 (130 KB/s) - ‘mysql57-community-release-el7-11.noarch.rpm’ saved [25680/25680]

3 安装mysql

执行安装mysql源命令

[root@lsdBKusFRn ~]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
Last metadata expiration check: 0:19:31 ago on Sat 28 May 2022 05:53:32 PM CST.
Dependencies resolved.
========================================================================================================================================================================
 Package                                              Architecture                      Version                           Repository                               Size
========================================================================================================================================================================
Installing:
 mysql57-community-release                            noarch                            el7-11                            @commandline                             25 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package

Total size: 25 k
Installed size: 31 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                1/1 
  Installing       : mysql57-community-release-el7-11.noarch                                                                                                        1/1 
  Verifying        : mysql57-community-release-el7-11.noarch                                                                                                        1/1 

Installed:
  mysql57-community-release-el7-11.noarch                                                                                                                               

Complete!

再安装mysql服务器

[root@lsdBKusFRn ~]# yum -y install mysql-community-server
Last metadata expiration check: 0:19:36 ago on Sat 28 May 2022 05:53:34 PM CST.
Dependencies resolved.
========================================================================================================================================================================
 Package                                         Architecture                    Version                               Repository                                  Size
========================================================================================================================================================================
Installing:
 mysql-community-server                          x86_64                          5.7.38-1.el7                          mysql57-community                          178 M
Installing dependencies:
 mysql-community-client                          x86_64                          5.7.38-1.el7                          mysql57-community                           28 M
 mysql-community-common                          x86_64                          5.7.38-1.el7                          mysql57-community                          311 k
 mysql-community-libs                            x86_64                          5.7.38-1.el7                          mysql57-community                          2.6 M

Transaction Summary
========================================================================================================================================================================
Install  4 Packages

Total size: 208 M
Installed size: 890 M
Downloading Packages:
[SKIPPED] mysql-community-client-5.7.38-1.el7.x86_64.rpm: Already downloaded                                                                                           
[SKIPPED] mysql-community-common-5.7.38-1.el7.x86_64.rpm: Already downloaded                                                                                           
[SKIPPED] mysql-community-libs-5.7.38-1.el7.x86_64.rpm: Already downloaded                                                                                             
[SKIPPED] mysql-community-server-5.7.38-1.el7.x86_64.rpm: Already downloaded                                                                                           
MySQL 5.7 Community Server                                                                                                               27 MB/s |  27 kB     00:00    
GPG key at file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql (0x5072E1F5) is already installed
The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.. Failing package is: mysql-community-client-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-common-5.7.38-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-common-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-libs-5.7.38-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-libs-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-server-5.7.38-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-server-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: GPG check FAILED

注意到这一步有可能会报错:Error: GPG check FAILED,解决办法如下:添加–nogpgcheck参数

[root@lsdBKusFRn ~]# yum -y install mysql-community-server –nogpgcheck
Last metadata expiration check: 0:20:06 ago on Sat 28 May 2022 05:53:34 PM CST.
No match for argument: –nogpgcheck
Error: Unable to find a match: –nogpgcheck
[root@lsdBKusFRn ~]# yum install mysql-community-server --nogpgcheck
Last metadata expiration check: 0:20:17 ago on Sat 28 May 2022 05:53:34 PM CST.
Dependencies resolved.
========================================================================================================================================================================
 Package                                         Architecture                    Version                               Repository                                  Size
========================================================================================================================================================================
Installing:
 mysql-community-server                          x86_64                          5.7.38-1.el7                          mysql57-community                          178 M
Installing dependencies:
 mysql-community-client                          x86_64                          5.7.38-1.el7                          mysql57-community                           28 M
 mysql-community-common                          x86_64                          5.7.38-1.el7                          mysql57-community                          311 k
 mysql-community-libs                            x86_64                          5.7.38-1.el7                          mysql57-community                          2.6 M

Transaction Summary
========================================================================================================================================================================
Install  4 Packages

Total size: 208 M
Installed size: 890 M
Is this ok [y/N]: y
Downloading Packages:
[SKIPPED] mysql-community-client-5.7.38-1.el7.x86_64.rpm: Already downloaded                                                                                           
[SKIPPED] mysql-community-common-5.7.38-1.el7.x86_64.rpm: Already downloaded                                                                                           
[SKIPPED] mysql-community-libs-5.7.38-1.el7.x86_64.rpm: Already downloaded                                                                                             
[SKIPPED] mysql-community-server-5.7.38-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       : mysql-community-common-5.7.38-1.el7.x86_64                                                                                                     1/4 
  Installing       : mysql-community-libs-5.7.38-1.el7.x86_64                                                                                                       2/4 
  Running scriptlet: mysql-community-libs-5.7.38-1.el7.x86_64                                                                                                       2/4 
  Installing       : mysql-community-client-5.7.38-1.el7.x86_64                                                                                                     3/4 
  Running scriptlet: mysql-community-server-5.7.38-1.el7.x86_64                                                                                                     4/4 
  Installing       : mysql-community-server-5.7.38-1.el7.x86_64                                                                                                     4/4 
  Running scriptlet: mysql-community-server-5.7.38-1.el7.x86_64                                                                                                     4/4 
[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.

  Verifying        : mysql-community-client-5.7.38-1.el7.x86_64                                                                                                     1/4 
  Verifying        : mysql-community-common-5.7.38-1.el7.x86_64                                                                                                     2/4 
  Verifying        : mysql-community-libs-5.7.38-1.el7.x86_64                                                                                                       3/4 
  Verifying        : mysql-community-server-5.7.38-1.el7.x86_64                                                                                                     4/4 

Installed:
  mysql-community-client-5.7.38-1.el7.x86_64              mysql-community-common-5.7.38-1.el7.x86_64              mysql-community-libs-5.7.38-1.el7.x86_64             
  mysql-community-server-5.7.38-1.el7.x86_64             

Complete!

4 启动mysql

执行启动mysql命令

[root@lsdBKusFRn ~]# systemctl start mysqld.service

没有报错,没有输出,表示启动成功,执行以下命令验证是否已启动

[root@lsdBKusFRn ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-05-28 18:31:01 CST; 1min 15s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 234488 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 234416 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 234491 (mysqld)
    Tasks: 28 (limit: 6010)
   Memory: 362.4M
   CGroup: /system.slice/mysqld.service
           └─234491 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

May 28 18:30:19 lsdBKusFRn systemd[1]: Starting MySQL Server...
May 28 18:31:01 lsdBKusFRn systemd[1]: Started MySQL Server.

当有以上输出时,表示mysql已成功启动

5 设置mysql登录密码

系统默认为root生成一个临时密码,查找方式如下:

[root@lsdBKusFRn ~]# grep 'temporary password' /var/log/mysqld.log
2022-05-28T10:30:58.944136Z 1 [Note] A temporary password is generated for root@localhost: PBtw&U5%7u>t

得到root密码是:PBtw&U5%7u>t,用该密码登录

[root@lsdBKusFRn ~]# mysql -hlocalhost -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.38

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> 

如果需要修改root密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'QwerQwer@@@750';
Query OK, 0 rows affected (0.00 sec)

至此mysql安装完成,且可以正常登录

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在Linux上使用yum安装MySQL 8.0,你可以按照以下步骤进行操作: 1. 首先,你需要访问MySQL官方网站的安装教程,链接为\[1\]。这个教程提供了关于在Linux安装MySQL的详细说明。 2. 根据你的Linux系统版本,选择合适的MySQL版本。例如,如果你的系统是CentOS 7.6,你可以使用命令`yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm`来安装MySQL的yum数据源。请确保在安装过程中按照提示输入两次"y"来确认安装。 3. 如果你的Linux系统已经安装了Docker,你也可以考虑使用Docker来安装MySQL。你可以参考\[3\]中提供的Docker安装MySQL 8并配置远程连接的教程。 总结起来,要在Linux上使用yum安装MySQL 8.0,你需要先安装MySQL的yum数据源,然后根据系统版本选择合适的MySQL版本进行安装。希望这些信息对你有帮助。 \[1\] https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html#yum-repo-installing-mysql \[2\] 引用内容中没有提供相关信息 \[3\] 引用内容中没有提供相关信息 #### 引用[.reference_title] - *1* [Linux基于yum安装mysql8](https://blog.csdn.net/shenya2/article/details/81322036)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [linux yum安装mysql8](https://blog.csdn.net/qq_26462567/article/details/102475057)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

looken1024

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值