Linux 下安装MySQL 5.7与 8.0详情

server/2024/9/25 23:18:33/

官网资源下载

1、检查 /tmp 临时目录权限,将 /tmp 目录及所有子目录和文件的权限设置为所有用户可读、写和执行

[root@localhost ~]# chmod -R 777 /tmp

2、安装前检查相关依赖

2.1、查找是否安装了 libaio 包。libaio 是 Linux 下异步 I/O 库的一个实现,用于提供异步 I/O 支持。

[root@localhost ~]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64

2.2、查找是否安装了 net-tools 包。net-tools 包含了一些网络管理工具,如 ifconfig、netstat 等。通过 rpm -qa 命令可以列出系统上所有已安装的 RPM 包,然后通过管道 | 将结果传递给 grep 命令,用于过滤出包含 “net-tools” 字样的行。

[root@localhost ~]# rpm -qa|grep net-tools
net-tools-2.0-0.25.20131004git.el7.x86_64

3、安装

3.1、将下载的安装包通过 finals hell等相关工具上传至CentOS 7中,切换路径并列出目录中的文件和子目录

3.1.1、 MySQL8.0需要的安装包如下

[root@localhost mysql80]# ll
总用量 489744
-rw-r--r--. 1 root root  47810444 4月  20 02:05 mysql-community-client-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 root root    193616 4月  20 02:04 mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 root root    628904 4月  20 02:04 mysql-community-common-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 root root   4240320 4月  20 02:04 mysql-community-libs-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 448614076 4月  20 02:08 mysql-community-server-8.0.25-1.el7.x86_64.rpm

3.1.2、MySQL 5.7 需要的安装包如下:

[root@rqtanc mysql57]# ll
总用量 252444
-rw-r--r--. 1 root root  45109364 4月  20 01:15 mysql-community-client-5.7.28-1.el7.x86_64.rpm
-rw-r--r--. 1 root root    318768 4月  20 01:13 mysql-community-common-5.7.28-1.el7.x86_64.rpm
-rw-r--r--. 1 root root   4374364 4月  20 01:13 mysql-community-libs-5.7.28-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 208694824 4月  20 01:16 mysql-community-server-5.7.28-1.el7.x86_64.rpm

3.2 按序安装

3.2.1、安装 mysql-community-common-8.0.25-1.el7.x86_64.rpm(5.7同理)

[root@localhost mysql80]# rpm -ivh mysql-community-common-8.0.25-1.el7.x86_64.rpm 
警告:mysql-community-common-8.0.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-common-8.0.25-1.e################################# [100%]

3.2.2、安装 mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm

[root@localhost mysql80]# rpm -ivh mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm 
警告:mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-client-plugins-8.################################# [100%]

3.2.3、 安装 mysql-community-libs-8.0.25-1.el7.x86_64.rpm (5.7同理)

[root@localhost mysql80]# rpm -ivh mysql-community-libs-8.0.25-1.el7.x86_64.rpm 
警告:mysql-community-libs-8.0.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:mariadb-libs 被 mysql-community-libs-8.0.25-1.el7.x86_64 取代

3.2.3.1、 错误:依赖检测失败: mariadb-libs 被 mysql-community-libs-8.0.25-1.el7.x86_64 取代,执行以下命令,完成后 再次执行 3.2.3

[root@localhost mysql80]# yum remove mysql-libs
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.68-1.el7 将被 删除
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在检查事务
---> 软件包 postfix.x86_64.2.2.10.1-9.el7 将被 删除
--> 解决依赖关系完成依赖关系解决===================================================================================================================================================================================Package                                     架构                                  版本                                             源                                        大小
===================================================================================================================================================================================
正在删除:mariadb-libs                                x86_64                                1:5.5.68-1.el7                                   @anaconda                                4.4 M
为依赖而移除:postfix                                     x86_64                                2:2.10.1-9.el7                                   @anaconda                                 12 M事务概要
===================================================================================================================================================================================
移除  1 软件包 (+1 依赖软件包)安装大小:17 M
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。正在删除    : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                  1/2 正在删除    : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                             2/2 验证中      : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                             1/2 验证中      : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                  2/2 删除:mariadb-libs.x86_64 1:5.5.68-1.el7                                                                                                                                               作为依赖被删除:postfix.x86_64 2:2.10.1-9.el7                                                                                                                                                    完毕!

3.2.4 安装mysql-community-client-8.0.25-1.el7.x86_64.rpm (5.7同理)

[root@localhost mysql80]# rpm -ivh mysql-community-client-8.0.25-1.el7.x86_64.rpm 
警告:mysql-community-client-8.0.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-client-8.0.25-1.e################################# [100%]

3.2.5 安装 mysql-community-server-8.0.25-1.el7.x86_64.rpm (5.7同理)

[root@localhost mysql80]# rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm 
警告:mysql-community-server-8.0.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-server-8.0.25-1.e################################# [100%]

3.3、查看MySQL安装版本

[root@localhost mysql80]# mysql --version
mysql  Ver 8.0.25 for Linux on x86_64 (MySQL Community Server - GPL)

3.4、初始化服务

[root@localhost mysql80]# mysqld --initialize --user=mysql

说明:initialize 选项默认以“安全”模式来初始化,将root 用户生成一个密码并标记为已过期,登录后重新设置,临时密码会保存在日志中。 查看密码执行以下命令:

[root@localhost mysql80]# cat /var/log/mysqld.log
2024-04-20T09:36:54.908453Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.25) initializing of server in progress as process 7431
2024-04-20T09:36:55.233056Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-04-20T09:37:03.480555Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-04-20T09:37:10.045138Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: se)Xw%po6fuy

3.5、查看MySQL运行状态

[root@localhost mysql80]# systemctl status mysqldmysqld.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

3.6、启动MySQL服务并再次查看运行状态

[root@localhost mysql80]# systemctl start mysqld
[root@localhost mysql80]# systemctl status mysqldmysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since 六 2024-04-20 02:43:42 PDT; 12s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 14736 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 15031 (mysqld)Status: "Server is operational"Tasks: 38CGroup: /system.slice/mysqld.service└─15031 /usr/sbin/mysqld4月 20 02:42:44 localhost.localdomain systemd[1]: Starting MySQL Server...
4月 20 02:43:42 localhost.localdomain systemd[1]: Started MySQL Server.

3.7、查看MySQL服务是否自启动

[root@localhost mysql80]# systemctl list-unit-files|grep mysqld.service
mysqld.service                                enabled 

3.7.1 、 如果不希望自行启动,执行以下命令进行设置

[root@localhost mysql80]# systemctl disable mysqld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/mysqld.service.
[root@localhost mysql80]# systemctl list-unit-files|grep mysqld.service
mysqld.service                                disabled

3.7.2、 如果需要设置自行启动,执行以下命令进行设置

[root@localhost mysql80]# systemctl enable mysqld.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost mysql80]# systemctl list-unit-files|grep mysqld.service
mysqld.service                                enabled 

4、MySQL登录

4.1、首次登录,执行 cat /var/log/mysqld.log 查看默认密码并进行登录

[root@localhost mysql80]# cat /var/log/mysqld.log
2024-04-20T09:36:54.908453Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.25) initializing of server in progress as process 7431
2024-04-20T09:36:55.233056Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-04-20T09:37:03.480555Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-04-20T09:37:10.045138Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: se)Xw%po6fuy
2024-04-20T09:43:20.118202Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.25) starting as process 15031
2024-04-20T09:43:20.641330Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-04-20T09:43:37.479110Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-04-20T09:43:40.281934Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2024-04-20T09:43:42.214332Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-04-20T09:43:42.214736Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-04-20T09:43:42.402257Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.25'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
[root@localhost mysql80]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25Copyright (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.mysql> 

4.2、修改密码

mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.09 sec)

4.3、 退出并重新登录

5、远程连接

5.1、查看当前防火墙状态

[root@localhost mysql80]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: active (running) since 六 2024-04-20 00:38:18 PDT; 2h 35min agoDocs: man:firewalld(1)Main PID: 689 (firewalld)Tasks: 2CGroup: /system.slice/firewalld.service└─689 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid4月 20 00:38:10 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
4月 20 00:38:18 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
4月 20 00:38:19 localhost.localdomain firewalld[689]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed ...ng it now.
Hint: Some lines were ellipsized, use -l to show in full.

5.2、开放端口

[root@localhost mysql80]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success

5.3、重新加载防火墙

[root@localhost mysql80]# firewall-cmd --reload

5.4、验证:使用以下命令验证防火墙是否正确配置来允许 3306 端口的流量通过:

[root@localhost ~]# firewall-cmd --zone=public --list-ports
3306/tcp

5.5、使用DataGrip等相关工具进行连接
在这里插入图片描述
解决方式:
5.5.1登录mysql

[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.25 MySQL Community Server - GPLCopyright (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.

5.5.2、查看相关数据库,使用mysql数据库,查看user表相关信息如下,root用户只允许本机连接

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (1.54 sec)
mysql> use mysql;
Database changed
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

5.5.3、修改root 用户对应的host,建议严格校验,此处设置为允许任何客户端进行连接

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (2.21 sec)
Rows matched: 1  Changed: 1  Warnings: 0

5.5.4、刷新权限使其生效

mysql> flush privileges;
Query OK, 0 rows affected (0.64 sec)

在这里插入图片描述


http://www.ppmy.cn/server/5486.html

相关文章

【设计模式】6、bridge 桥接模式

六、bridge 桥接模式 桥接设计模式 复杂逻辑拆分: 如果需要完成复杂的逻辑,可以把复杂逻辑设计为接口,内部再拆分为若干接口。这样复杂的逻辑会被拆分开,方便解耦。 例如:如果遥控器控制设备。可以遥控器设计为复杂…

【c++】vector的使用

🔥个人主页:Quitecoder 🔥专栏:c笔记仓 朋友们大家好,我们本篇来到一个新的容器,vector的讲解和使用 目录 1.vector简单介绍2.vector的使用2.1构造函数2.2遍历vector2.3对容量操作2.4vector的增删查改 1.v…

Parade Series - CoreAudio Loopback

Scenario 鉴于业务场景需要, 经过技术路径探索, 发现 comtypes 兼容性过于混乱,故而考虑整合一个 CoreAudio 的轮子dll来解决实际问题!std::StringStream ⇒ std::ios::binary ⇒ std::ofstream Loopback.dll #ifndef _DLL_C…

OpenHarmony实战开发-如何使用弹簧曲线实现抖动动画及手机振动效果案例。

介绍 本示例介绍使用vibrator.startVibration方法实现手机振动效果,用keyframeAnimateTo关键帧动画实现点击后的抖动动画。 效果图预览 使用说明 1.加载完成后显示登录界面,未勾选协议时点击一键登录按钮会触发手机振动效果和提示文本的抖动动画。 实…

「51媒体」新闻媒体邀约如何进行媒体宣传(方法)

传媒如春雨,润物细无声,大家好,我是51媒体网胡老师。 新闻媒体邀约进行媒体宣传是一个策略性的过程,旨在吸引媒体的注意力并促使其对特定事件、产品发布或企业活动进行报道。以下是一些关键步骤和策略: 制定媒体传播方…

某零售企业招聘管理体系搭建咨询项目

科学岗位分析,改善招聘流程,提高招聘及时率随着公司不断发展壮大,企业规模逐渐增大,部门设置也日益增多,因此对人员的需求也日益提高。但是目前该企业在人员招聘方面逐渐暴露出一些诸如岗位分析不到位、缺乏整体面试计…

[StartingPoint][Tier2]Base

Task 1 Which two TCP ports are open on the remote host? (远程服务器开放了哪两个TCP端口?) $ nmap -sC -sV 10.129.234.232 22,80 Task 2 What is the relative path on the webserver for the login page? (相关的登录页面路径是什么?) /login/login.php Task 3 …

[论文阅读链接]

CVPR2023:Learning Human-to-Robot Handovers from Point Clouds http://t.csdnimg.cn/OfSnShttp://t.csdnimg.cn/OfSnS仿真工具:dm_control: Software and Tasks for Continuous Control dm_control 翻译: Software and Tasks for Continuous Control…