Centos9 离线安装 MYSQL8

centos 9 离线安装 mysql 8

参考教程

1. 官网下载mysql

下载地址

2. 将文件传输到Centos中解压

软件全部安装到了/opt中

bash 复制代码
在opt中新建mysql目录,解压到mysql目录中
tar -xvf mysql压缩文件 mysql
shell 复制代码
[root@centoshost mysql]# ls
mysql-community-client-8.4.5-1.el9.aarch64.rpm
mysql-community-client-debuginfo-8.4.5-1.el9.aarch64.rpm
mysql-community-client-plugins-8.4.5-1.el9.aarch64.rpm
mysql-community-client-plugins-debuginfo-8.4.5-1.el9.aarch64.rpm
mysql-community-common-8.4.5-1.el9.aarch64.rpm
mysql-community-debuginfo-8.4.5-1.el9.aarch64.rpm
mysql-community-debugsource-8.4.5-1.el9.aarch64.rpm
mysql-community-devel-8.4.5-1.el9.aarch64.rpm
mysql-community-icu-data-files-8.4.5-1.el9.aarch64.rpm
mysql-community-libs-8.4.5-1.el9.aarch64.rpm
mysql-community-libs-compat-8.4.5-1.el9.aarch64.rpm
mysql-community-libs-compat-debuginfo-8.4.5-1.el9.aarch64.rpm
mysql-community-libs-debuginfo-8.4.5-1.el9.aarch64.rpm
mysql-community-server-8.4.5-1.el9.aarch64.rpm
mysql-community-server-debug-8.4.5-1.el9.aarch64.rpm
mysql-community-server-debug-debuginfo-8.4.5-1.el9.aarch64.rpm
mysql-community-server-debuginfo-8.4.5-1.el9.aarch64.rpm
mysql-community-test-8.4.5-1.el9.aarch64.rpm
mysql-community-test-debuginfo-8.4.5-1.el9.aarch64.rpm

3. 安装

shell 复制代码
[root@centoshost mysql]# rpm -ivh mysql-community-common-8.4.5-1.el9.aarch64.rpm 
警告:mysql-community-common-8.4.5-1.el9.aarch64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
        软件包 mysql-community-common-8.4.5-1.el9.aarch64 已经安装
[root@centoshost mysql]# rpm -ivh mysql-community-client-plugins-8.4.5-1.el9.aarch64.rpm 
警告:mysql-community-client-plugins-8.4.5-1.el9.aarch64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
        软件包 mysql-community-client-plugins-8.4.5-1.el9.aarch64 已经安装
[root@centoshost mysql]# rpm -ivh mysql-community-libs-8.4.5-1.el9.aarch64.rpm 
警告:mysql-community-libs-8.4.5-1.el9.aarch64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
        软件包 mysql-community-libs-8.4.5-1.el9.aarch64 已经安装
[root@centoshost mysql]# rpm -ivh mysql-community-client-8.4.5-1.el9.aarch64.rpm 
警告:mysql-community-client-8.4.5-1.el9.aarch64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
        软件包 mysql-community-client-8.4.5-1.el9.aarch64 已经安装
[root@centoshost mysql]# rpm -ivh mysql-community-icu-data-files-8.4.5-1.el9.aarch64.rpm 
警告:mysql-community-icu-data-files-8.4.5-1.el9.aarch64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
        软件包 mysql-community-icu-data-files-8.4.5-1.el9.aarch64 已经安装
  • 安装server部分时报错
shell 复制代码
[root@centoshost mysql]# rpm -ivh mysql-community-server-8.4.5-1.el9.aarch64.rpm 
警告:mysql-community-server-8.4.5-1.el9.aarch64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
错误:依赖检测失败:
        /usr/bin/perl 被 mysql-community-server-8.4.5-1.el9.aarch64 需要
        libtirpc.so.3()(64bit) 被 mysql-community-server-8.4.5-1.el9.aarch64 需要
        libtirpc.so.3(TIRPC_0.3.0)(64bit) 被 mysql-community-server-8.4.5-1.el9.aarch64 需要
        libtirpc.so.3(TIRPC_0.3.3)(64bit) 被 mysql-community-server-8.4.5-1.el9.aarch64 需要
        net-tools 被 mysql-community-server-8.4.5-1.el9.aarch64 需要
  • 安装需要的3个软件:
shell 复制代码
yum install perl
yum install libtirpc
yum install net-tools
  • 继续安装:
javascript 复制代码
[root@centoshost mysql]# rpm -ivh mysql-community-server-8.4.5-1.el9.aarch64.rpm 
警告:mysql-community-server-8.4.5-1.el9.aarch64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
        软件包 mysql-community-server-8.4.5-1.el9.aarch64 已经安装

4. 初始化mysql,并修改mysql的文件权限

shell 复制代码
[root@centoshost /]# mysqld --initialize
[root@centoshost /]# cd /var/lib
[root@centoshost lib]# chmod -R 777 mysql

5. 查看mysql密码

bash 复制代码
[root@centoshost mysql]# cat /var/log/mysqld.log | grep password
2025-04-19T23:33:47.943889Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: (KfbEDtGT9Ct

6. 登录mysql

bash 复制代码
[root@centoshost lib]# mysql -uroot -p
Enter password: 
  • 如果输入密码老是报错,可以免密码登录,修改完root密码以后记得改回来
    1. 停止 MySQL 服务:sudo systemctl stop mysqld
    2. 以跳过权限验证的方式启动 MySQL:
      编辑 MySQL 的配置文件(通常是 /etc/my.cnf 或 /etc/mysql/my.cnf),在 [mysqld] 部分添加 skip-grant-tables,保存并退出编辑器。
    3. 启动MySQL服务sudo systemctl start mysqld
    4. 无需密码直接登录 MySQL:mysql -uroot
  • 修改root密码:
sql 复制代码
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)

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

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

7. 在mysql中创建远程访问的用户,可以修改root,也可以新增用户

sql 复制代码
CREATE USER 'remote_user'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
  • 至此已经安装完成可以在数据库可视化工具中使用数据库了,如果不能访问,可能是防火墙的问题
  • 修改MYSQL配置:
    配置文件/etc/my.cnf
javascript 复制代码
   [mysqld]
   character_set_server=utf8mb4
   collation_server=utf8mb4_general_ci

8. 设置mysql开机自启动

bash 复制代码
sudo systemctl enable mysqld
相关推荐
蒲公英源码1 小时前
uniapp开源ERP多仓库管理系统
mysql·elementui·uni-app·php
小码过河.2 小时前
告别 mysqldump 痛点!用 mydumper 实现 MySQL 高效备份与恢复
数据库·mysql
是2的10次方啊2 小时前
MySQL索引优化实战:原则速查与踩坑案例(实战篇)
mysql
遇见火星3 小时前
Linux 网络配置实战:RHEL/CentOS 7+ 永久静态路由配置与优先级调整全攻略
linux·网络·centos·静态路由·centos 7
Hello.Reader5 小时前
基于 Flink CDC 的 MySQL → Kafka Streaming ELT 实战
mysql·flink·kafka
L.EscaRC6 小时前
浅析MySQL InnoDB存储引擎的MVCC实现原理
数据库·mysql
-指短琴长-13 小时前
MySQL快速入门——基本查询(下)
android·mysql·adb
August_._14 小时前
【MySQL】SQL语法详细总结
java·数据库·后端·sql·mysql·oracle
林北北的霸霸17 小时前
django初识与安装
android·mysql·adb
森语林溪17 小时前
大数据环境搭建从零开始(十四)CentOS 7 系统更新源更换详解:阿里云镜像源配置完整指南
大数据·linux·运维·阿里云·centos