linux离线安装mysql

一、安装

1、下载MySQL离线安装包

下载地址:https://dev.mysql.com/downloads/mysql/
选择如下:
在这里插入图片描述
在这里插入图片描述

2、上传tar压缩包到服务器

这里也可以新建文件夹放也行,我就通过xftp软件上传放在opt的目录下
在这里插入图片描述

3、删除原有的mariadb

先通过rpm -qa|grep mariadb命令查看是否安装mariadb-libs库,如果能查的到就通过rpm -e --nodeps mariadb-libs命令删除,不删除的话等下安装MySQL会出现报错,有冲突。

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

4、解压缩mysql离线安装包

通过 cd /opt 进入之前存放的数据库压缩包路径,然后ls 打印下文件信息,最后通过tar -xvf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar来解压文件,记得压缩包名要核对下,每个版本的名称不一致,不然解压找不到文件。

[root@localhost /]# cd /opt
[root@localhost opt]# ls
mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar  rh
[root@localhost opt]# tar -xvf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar
tar: mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar:无法 open: 没有那个文件或目录
tar: Error is not recoverable: exiting now
[root@localhost opt]# tar -xvf mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.2.0-1.el7.x86_64.rpm
mysql-community-client-plugins-8.2.0-1.el7.x86_64.rpm
mysql-community-common-8.2.0-1.el7.x86_64.rpm
mysql-community-debuginfo-8.2.0-1.el7.x86_64.rpm
mysql-community-devel-8.2.0-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.2.0-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.2.0-1.el7.x86_64.rpm
mysql-community-libs-8.2.0-1.el7.x86_64.rpm
mysql-community-libs-compat-8.2.0-1.el7.x86_64.rpm
mysql-community-server-8.2.0-1.el7.x86_64.rpm
mysql-community-server-debug-8.2.0-1.el7.x86_64.rpm
mysql-community-test-8.2.0-1.el7.x86_64.rpm

5、安装rmp包

逐个安装,按顺序来,如果包名不一致,记得改,命令如下:

rpm -ivh mysql-community-common-8.2.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.2.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.2.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.2.0-1.el7.x86_64.rpm

出现错误
错误的提示也很明细,提示我们提前安装mysql-community-client-plugins = 8.2.0-1.el7这个rpm包,之前解压的tar文件都有

[root@localhost opt]# rpm -ivh mysql-community-libs-8.2.0-1.el7.x86_64.rpm
警告:mysql-community-libs-8.2.0-1.el7.x86_64.rpm:V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
错误:依赖检测失败:
	mysql-community-client-plugins = 8.2.0-1.el7 被 mysql-community-libs-8.2.0-1.el7.x86_64 需要

解决方法
目前安装rpm -ivh mysql-community-libs-8.2.0-1.el7.x86_64.rpm出现的需要mysql-community-client-plugins = 8.2.0-1.el7这个依赖,所以找到之前我们解压的包,提前安装mysql-community-client-plugins = 8.2.0-1.el7.x86_64.rpm,后面在安装就不会报错了,剩下的rpm包报错也是这样子处理

[root@localhost opt]# rpm -ivh  mysql-community-client-plugins-8.2.0-1.el7.x86_64.rpm
警告:mysql-community-client-plugins-8.2.0-1.el7.x86_64.rpm:V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-plugins-8.################################# [100%]
[root@localhost opt]# rpm -ivh mysql-community-libs-8.2.0-1.el7.x86_64.rpm
警告:mysql-community-libs-8.2.0-1.el7.x86_64.rpm:V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-8.2.0-1.el7 ################################# [100%]

6、查看是否安装成功

[root@localhost opt]# rpm -qa|grep mysql
mysql-community-icu-data-files-8.2.0-1.el7.x86_64
mysql-community-client-plugins-8.2.0-1.el7.x86_64
mysql-community-server-8.2.0-1.el7.x86_64
mysql-community-libs-8.2.0-1.el7.x86_64
mysql-community-client-8.2.0-1.el7.x86_64
mysql-community-common-8.2.0-1.el7.x86_64

二、启动MySQL服务

1、查看MySQL服务状态

[root@localhost opt]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: 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

发现状态是出于enabled(启动)
在这里插入图片描述

2、关闭MySQL服务

[root@localhost opt]# systemctl stop mysqld

3、初始化数据库

成功了也没什么提示

[root@localhost opt]# mysqld --initialize --console

4、目录授权

在 MySQL 中,我们可以应用 chown 命令来控制数据库的读写权限。例如,下列命令的作用是将 MySQL 数据库的所有者和所属组修改为 mysql,以保证数据库的安全性:

[root@localhost opt]# chown -R mysql:mysql /var/lib/mysql/

通过 chown 命令修改 MySQL 数据库的所有者和所属组,我们可以确保 MySQL 数据库的安全性和稳定性。同时,我们也需要注意文件权限的改变是否可能会对数据库的正常运行产生影响,特别是在生产环境中,我们需要谨慎处理,避免对系统造成不必要的损失。
注意事项

  1. chown 命令需要以 root 权限运行,否则可能会被拒绝访问。
  2. 在修改文件权限之前,需要先备份重要数据,以避免不必要的损失。
  3. 如果文件权限发生改变,可能会影响 MySQL 数据库的正常运行,因此需要谨慎处理。
  4. 在修改 MySQL 数据库的所有者和所属组时,需要确保没有正在运行的 MySQL 进程,否则可能会导致服务不可用。

5、启动MySQL服务

通过systemctl start mysqld开启服务,在通过netstat -tlpn执行最后一行可以看到我们的MySQL服务的运行端口进程,说明已经成功,接下来是进去修改初始密码。

[root@localhost opt]# systemctl start mysqld
[root@localhost opt]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      758/rpcbind         
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1515/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1239/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1240/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1448/master         
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      2681/sshd: root@pts 
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      55358/sshd: root@pt 
tcp6       0      0 :::111                  :::*                    LISTEN      758/rpcbind         
tcp6       0      0 :::22                   :::*                    LISTEN      1239/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1240/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1448/master         
tcp6       0      0 ::1:6010                :::*                    LISTEN      2681/sshd: root@pts 
tcp6       0      0 ::1:6011                :::*                    LISTEN      55358/sshd: root@pt 
tcp6       0      0 :::33060                :::*                    LISTEN      56532/mysqld        
tcp6       0      0 :::3306                 :::*                    LISTEN      56532/mysqld

三、数据库操作

1、查看临时密码

通过命令:cat /var/log/mysqld.log 执行,root@localhost:后面是密码,建议登录的时候复制粘贴比较好。
在这里插入图片描述

2、用临时密码登录数据库

命令:mysql -u root -p 回车键
然后复制粘贴临时密码(输入时不会显示出来,输入完直接回车)

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

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.

3、修改临时密码

mysql> alter USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.03 sec)

4、授权远程连接

通过use mysql;使用MySQL库,执行select host, user, authentication_string from user;发现本地root用户是主机号localhost,所以需要将host主机改为%.

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 -A

Database changed
mysql> select host, user, authentication_string from user;
+-----------+------------------+------------------------------------------------------------------------+
| host      | user             | authentication_string                                                  |
+-----------+------------------+------------------------------------------------------------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | $A$005$-G(mK8y%."8%\!yMvV4bBdHE6w6YOCkQwWpTYBiKY3Jw6Ph1C61xWKrSf. |
+-----------+------------------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)

通过update user set host = “%” where user=‘root’;修改主机为%,在查看下内容select host, user, authentication_string from user;,然后刷新权限flush privileges;

mysql> update user set host = "%" where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> select host, user, authentication_string from user;
+-----------+------------------+------------------------------------------------------------------------+
| host      | user             | authentication_string                                                  |
+-----------+------------------+------------------------------------------------------------------------+
| %         | root             | $A$005$-G(mK8y%."8%\!yMvV4bBdHE6w6YOCkQwWpTYBiKY3Jw6Ph1C61xWKrSf. |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
+-----------+------------------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)

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

5、使用navicat远程连接出现一下报错信息,这是linux防火墙处于开启状态导致的

在这里插入图片描述

6、远程防火墙设置

方案1:关闭防火墙

systemctl stop firewalld.service          #停止firewall
systemctl disable firewalld.service        #禁止firewall开机启动

方案2:开放访问端口
1、开放端口:firewall-cmd --zone=public --add-port=3306/tcp --permanent
命令含义:

--zone #作用域
--add-port=3306/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效

2、重启生效:firewall-cmd --reload
本人采用的是第二种方案

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

7、再次使用navicat连接,发现连接成功

在这里插入图片描述

四、总结

本人也是参考了一些信息,做了融合,参考文献如下。
https://www.cnblogs.com/quchunhui/p/11115339.html
https://blog.csdn.net/rao991207823/article/details/119840876
关于linux查看防火墙状态的内容可以参考这个
https://blog.csdn.net/qq_36640713/article/details/106553833

  • 13
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于Linux离线安装Telnet,你可以按照以下步骤进行操作: 1. 首先,你需要准备好以下软件包:telnet-0.17-47.el6.x86_64.rpm、xinetd-2.3.15-20.fc27.x86_64.rpm、telnet-server-0.17-47.el6.x86_64.rpm。 2. 在开始安装之前,你可以先检查这些软件包是否已经安装在系统中。可以使用命令`rpm -qa | grep telnet`来查询已安装的telnet相关软件包。如果已经安装了,可以先将其卸载以确保安装的干净。 3. 使用命令`rpm -e telnet xinetd telnet-server`来卸载已安装的telnet相关软件包。这样可以确保安装过程中没有冲突。如果你不确定哪些软件包已经安装了,可以将它们都卸载后再进行安装。 4. 确保你已经准备好了上述的软件包,可以通过USB、网络等方式将它们传输到Linux系统中。 5. 使用命令`rpm -ivh telnet-0.17-47.el6.x86_64.rpm xinetd-2.3.15-20.fc27.x86_64.rpm telnet-server-0.17-47.el6.x86_64.rpm`来安装telnet及其相关软件包。这里的命令中的参数`-ivh`分别表示安装(install)、显示详细信息(verbose)、显示安装进度(hash marks)。 6. 安装完成后,你可以通过`telnet localhost`命令来验证telnet是否成功安装并运行。 请注意,以上步骤仅适用于离线安装,如果有可用的软件包管理工具,推荐使用它们来安装telnet,因为这样可以更方便地解决依赖关系,并自动处理安装过程中的问题。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [linux离线安装telnet](https://download.csdn.net/download/greenhills555/9984427)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [linux centos7 离线安装telnet_b13001216978的博客-CSDN博客_linux离线安装telnet1](https://download.csdn.net/download/weixin_35775446/86331337)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值