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
相关推荐
tan180°5 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
DuelCode6 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
幽络源小助理6 小时前
SpringBoot基于Mysql的商业辅助决策系统设计与实现
java·vue.js·spring boot·后端·mysql·spring
爬山算法7 小时前
MySQL(116)如何监控负载均衡状态?
数据库·mysql·负载均衡
BD_Marathon9 小时前
设置LInux环境变量的方法和区别_Ubuntu/Centos
linux·ubuntu·centos
xmode10 小时前
centos7.9安装ffmpeg6.1和NASM、Yasm、x264、x265、fdk-aac、lame、opus解码器
ffmpeg·centos
星辰云-16 小时前
# Linux Centos系统硬盘分区扩容
linux·运维·centos·磁盘扩容
KellenKellenHao17 小时前
MySQL数据库主从复制
数据库·mysql
一只fish18 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(16)
数据库·mysql
kfepiza19 小时前
CentOS-7的"ifupdown"与Debian的"ifupdown"对比 笔记250706
centos