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
相关推荐
白鹭5 小时前
MySQL(多表查询练习)
数据库·mysql
AI 嗯啦9 小时前
SQL详细语法教程(三)mysql的函数知识
android·开发语言·数据库·python·sql·mysql
杰克尼10 小时前
mysql-条件查询案例
数据库·mysql
你那是什么调调12 小时前
`SHOW PROCESSLIST;` 返回列详解(含义 + 单位)
mysql
云心雨禅14 小时前
网站突然崩了,此站点遇到了致命错误!
服务器·mysql
运维自动化&云计算17 小时前
Centos虚拟机硬盘报错,根分区满,已用显示为负40G
linux·运维·centos
Menior_17 小时前
【补充】数据库中有关系统编码和校验规则的简述
数据库·mysql·oracle
Kay_Liang18 小时前
从聚合到透视:SQL 窗口函数的系统解读
大数据·数据库·sql·mysql·数据分析·窗口函数
诺亚凹凸曼19 小时前
MySQLinnodb引擎普通索引和唯一索引的区别
数据库·mysql
星空下的曙光1 天前
MySQL → SQL → DDL → 表操作 → 数据类型 知识链整理成一份系统的内容
数据库·sql·mysql