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
相关推荐
HtwHUAT4 分钟前
十、数据库day02--SQL语句01
数据库·sql·mysql·oracle
YGGP6 分钟前
【每日八股】复习 MySQL Day1:事务
数据库·mysql
Haku Coder2 小时前
网络安全零基础培训 L1-4 数据库基础
数据库·mysql·网络安全
chirrupy_hamal2 小时前
VMware Workstation 保姆级 Linux(CentOS) 创建教程(附 iso)
linux·centos·虚拟机
java1234_小锋3 小时前
MySQL为什么默认使用RR隔离级别?
数据库·mysql
Delphi菜鸟3 小时前
go+mysql+cocos实现游戏搭建
mysql·游戏·golang·gin·cocos2d
Java陈序员4 小时前
一个面向中小企业快速开发平台框架!
vue.js·spring boot·mysql
normaling4 小时前
十二,InnoDB引擎底层原理
mysql
Cachel wood4 小时前
大数据开发知识1:数据仓库
android·大数据·数据仓库·sql·mysql·算法·ab测试