欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > Centos7 rpm 安装 Mysql 8.0.28

Centos7 rpm 安装 Mysql 8.0.28

2024/11/30 12:48:15 来源:https://blog.csdn.net/zhangli_li520/article/details/140462455  浏览:    关键词:Centos7 rpm 安装 Mysql 8.0.28

Centos7 rpm 安装 Mysql 8.0.28

一、检查系统是否已经安装了Mysql 如果安装了则卸载

[root@iZbp1byzaznzn9jncxr010Z /]# rpm -qa | grep mysql[root@iZbp1byzaznzn9jncxr010Z /]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64

如果安装了 mysql ,mariadb 先卸载再安装mysql

卸载命令

[root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -qa | grep mariadb

rpm -e mysql  // 普通删除
rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删

二、下载安装包,检测安装环境,解压

Mysql 下载地址 https://dev.mysql.com/downloads/mysql/
如果不想用最新版,点击右侧的 Archives
在这里插入图片描述
查看服务器 系统版本 这个很重要,不然会安装有问题。

[root@iZbp1byzaznzn9jncxr010Z mysql]# uname -a
Linux iZbp1byzaznzn9jncxr010Z 3.10.0-1160.118.1.el7.x86_64 #1 SMP Wed Apr 24 16:01:50 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
[root@iZbp1byzaznzn9jncxr010Z mysql]#

我的系统是 el7 所以选择 OS Version: Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)

在这里插入图片描述
然后点击下载

将文件上传到服务器上 进行安装

三、安装 mysql

将文件上传至服务器 /opt/mysql/ 下
或者直接在服务器上下载

[root@iZbp1byzaznzn9jncxr010Z mysql]# wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
--2024-07-16 11:22:31--  https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 23.77.214.217, 2600:1417:4400:8ae::1d68, 2600:1417:4400:8b6::1d68
正在连接 cdn.mysql.com (cdn.mysql.com)|23.77.214.217|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:843008000 (804M) [application/x-tar]
正在保存至: “mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar”100%[===================================================================================================================================>] 843,008,000 12.0MB/s 用时 67s    2024-07-16 11:23:38 (12.1 MB/s) - 已保存 “mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar” [843008000/843008000])[root@iZbp1byzaznzn9jncxr010Z mysql]# ls
mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar

解压

[root@iZbp1byzaznzn9jncxr010Z mysql]# tar -xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar 
mysql-community-client-8.0.28-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
mysql-community-common-8.0.28-1.el7.x86_64.rpm
mysql-community-devel-8.0.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-server-8.0.28-1.el7.x86_64.rpm
mysql-community-test-8.0.28-1.el7.x86_64.rpm
[root@iZbp1byzaznzn9jncxr010Z mysql]# ls
mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar                mysql-community-devel-8.0.28-1.el7.x86_64.rpm            mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-client-8.0.28-1.el7.x86_64.rpm          mysql-community-embedded-compat-8.0.28-1.el7.x86_64.rpm  mysql-community-server-8.0.28-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm  mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm   mysql-community-test-8.0.28-1.el7.x86_64.rpm
mysql-community-common-8.0.28-1.el7.x86_64.rpm          mysql-community-libs-8.0.28-1.el7.x86_64.rpm

解压之后,这里有很多mysql 文件,我们只需要取其中六个
mysql-community-common-8.0.28-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-8.0.28-1.el7.x86_64.rpm
mysql-community-client-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
mysql-community-server-8.0.28-1.el7.x86_64.rpm

安装 一定要按照顺序安装 否则会出现 依赖不存的问题

[root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-common-8.0.28-1.e################################# [100%][root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -ivh mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-client-plugins-8.################################# [100%][root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-libs-8.0.28-1.el7################################# [100%][root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-client-8.0.28-1.e################################# [100%][root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-icu-data-files-8.################################# [100%][root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-server-8.0.28-1.e################################# [100%]

到这里安装成功

检查 版本 查看安装 信息

[root@iZbp1byzaznzn9jncxr010Z mysql]# mysql --version
mysql  Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)
[root@iZbp1byzaznzn9jncxr010Z mysql]# rpm -qa|grep -i mysql
mysql-community-client-8.0.28-1.el7.x86_64
mysql-community-common-8.0.28-1.el7.x86_64
mysql-community-libs-8.0.28-1.el7.x86_64
mysql-community-icu-data-files-8.0.28-1.el7.x86_64
mysql-community-client-plugins-8.0.28-1.el7.x86_64
mysql-community-server-8.0.28-1.el7.x86_64

初始化mysqld --initialize --user=mysql
查看 mysql 的初始密码 在文件最后的 一串 我这里密码是 ic+s5g_nIOpG

[root@iZbp1byzaznzn9jncxr010Z mysql]# mysqld --initialize --user=mysql
[root@iZbp1byzaznzn9jncxr010Z mysql]# cat /var/log/mysqld.log
2024-07-16T03:30:38.239991Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 4881
2024-07-16T03:30:38.246935Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-07-16T03:30:38.606152Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-07-16T03:30:39.685677Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ic+s5g_nIOpG

查看mysql 服务是否启动

[root@iZbp1byzaznzn9jncxr010Z mysql]# systemctl status mysqld
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: inactive (dead)Docs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.html

启动Mysql 服务

[root@iZbp1byzaznzn9jncxr010Z mysql]# systemctl start mysqld

查看服务状态


[root@iZbp1byzaznzn9jncxr010Z mysql]# systemctl status mysqld
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since 二 2024-07-16 11:31:10 CST; 5s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 5552 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 5594 (mysqld)Status: "Server is operational"Tasks: 38Memory: 373.2MCGroup: /system.slice/mysqld.service└─5594 /usr/sbin/mysqld7月 16 11:31:09 iZbp1byzaznzn9jncxr010Z systemd[1]: Starting MySQL Server...
7月 16 11:31:10 iZbp1byzaznzn9jncxr010Z systemd[1]: Started MySQL Server.

设置开机启动

[root@iZbp1byzaznzn9jncxr010Z mysql]# systemctl enable mysqld

配置 Mysql 根据自己需要,我这里使用默认配置

安装完成后,会自动生成 /etc/my.cnf 配置文件

安装了 mysql-community-server 组件,会:
a). 在 /etc/下生成 my.cnf 文件 和 my.cnf.d 文件夹

b). 在/var/lib/下生产以下三个文件夹

c). 在/var/log/ 下生成 mysqld.log 文件

d). 在/var/run/ 下生成 mysqld 目录

[root@iZbp1byzaznzn9jncxr010Z /]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_passworddatadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

四、配置mysql

1、登录mysql 使用刚刚查看的密码 ic+s5g_nIOpG 登录

[root@iZbp1byzaznzn9jncxr010Z mysql]# mysql -uroot -p'ic+s5g_nIOpG'
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.28Copyright (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>

2、修改密码

mysql> alter user 'root'@'localhost' IDENTIFIED BY 'admin123456';
Query OK, 0 rows affected (0.01 sec)

3、配置远程连接

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -Amysql> select host from user where user='root';
+-----------+
| host      |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)mysql> update user set host = '%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

4、使用客户端连接

使用客户端连接会出现
在这里插入图片描述
这是因为 mysql8.0较旧版更新了密码加密方式。。。
plugin(插件)格式被更新为caching_sha2_password,所以我们只需要改为旧版本mysql_native_password即可

更新一下

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'admin123456';
Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

再次登录验证,连接正常
在这里插入图片描述

到此安装结束

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com