本篇文章详细讲解如何在银河麒麟 V10 (Kylin V10)系统中离线安装 MySQL 8.0 数据库。

本文适用于银河麒麟服务器操作系统V10 aarch64 版。

MySQL 安装包下载地址:

百度网盘:mysql_8.0_arm64.zip

下载以后,把压缩包上传到服务器并解压。

按顺序安装如下六个 rpm 包:

1
2
3
4
5
6
7
rpm -ivh mysql-community-common-8.0.46-1.el8.aarch64.rpm
rpm -ivh mysql-community-client-plugins-8.0.46-1.el8.aarch64.rpm
rpm -ivh mysql-community-libs-8.0.46-1.el8.aarch64.rpm
rpm -ivh mysql-community-client-8.0.46-1.el8.aarch64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.46-1.el8.aarch64.rpm
rpm -ivh mysql-community-server-8.0.46-1.el8.aarch64.rpm

1
2
3
4
5
6
7
8
9
# 启动 MySQL
systemctl start mysqld

# 设置开机启动
systemctl enable mysqld

# 查看运行状态(可选)
systemctl status mysqld

/var/log/mysqld.log 日志文件中找到 mysql 临时密码,类似如下的一行日志:

1
A temporary password is generated for root@localhost: O*!srpLCo0We

使用如下命令:

1
cat /var/log/mysqld.log

从日志中寻找临时密码:

1
2
3
4
5
6
7
8
9
10
11
2026-07-01T08:54:34.077096Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.46) initializing of server in progress as process 263190
2026-07-01T08:54:34.138902Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-07-01T08:54:36.726802Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-07-01T08:54:42.794517Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: O*!srpLCo0We
2026-07-01T08:54:54.622793Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.46) starting as process 263241
2026-07-01T08:54:54.637145Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-07-01T08:54:55.356227Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-07-01T08:54:56.006222Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2026-07-01T08:54:56.006390Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2026-07-01T08:54:56.059134Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2026-07-01T08:54:56.059482Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.46' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.

使用临时密码登录 MySQL:

1
mysql -uroot -p

输完以上命令,按回车以后,粘贴密码,再按回车,就登录 MySQL 了。

登录 MySQL 以后执行 SQL 修改 root 密码:

1
2
3
4
5
6
7
8
9
10
11
-- 首先改一个强密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Abcd@1234';

-- 策略改为LOW:只校验密码长度,不再要求大小写、特殊字符(临时)
SET GLOBAL validate_password.policy = LOW;
-- 把最小密码长度从默认8改为4(临时)
SET GLOBAL validate_password.length = 6;

-- 再修改为实际正在使用的密码(此处为示例密码,请改为实际使用的密码)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

停止 MySQL:

1
systemctl stop mysqld

打开 MySQL 配置文件:

1
vim /etc/my.cnf

在原有 my.cnf 的 [mysqld] 下面接着粘贴如下几行配置:

1
2
3
4
5
6
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
default-authentication-plugin=mysql_native_password
default-time-zone='+8:00'

在 my.cnf 的最末尾追加如下几行配置(可选):

1
2
3
[client]
default-character-set=utf8mb4

保存退出。启动 MySQL:

1
systemctl start mysqld

登录MySQL,使用以下几个SQL语句查看配置是否正确:

1
2
3
4
5
6
7
8
SHOW VARIABLES LIKE '%character%';

SHOW VARIABLES LIKE '%collation%';

SHOW VARIABLES LIKE 'default_authentication_plugin';

SELECT user,host,plugin FROM mysql.user WHERE user='root';

主要验证打印的配置项和下面列出的配置项是否一致。

1
2
3
4
5
6
7
8
9
mysql> SHOW VARIABLES LIKE '%character%';
+-------------------------------------------------+--------------------------------+
| Variable_name | Value |
+-------------------------------------------------+--------------------------------+
| character_set_client | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
+-------------------------------------------------+--------------------------------+
1
2
3
4
5
6
7
mysql> SHOW VARIABLES LIKE '%collation%';
+-------------------------------+--------------------+
| Variable_name | Value |
+-------------------------------+--------------------+
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+-------------------------------+--------------------+
1
2
3
4
5
6
mysql> SHOW VARIABLES LIKE 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| default_authentication_plugin | mysql_native_password |
+-------------------------------+-----------------------+
1
2
3
4
5
6
mysql> SELECT user,host,plugin FROM mysql.user WHERE user='root';
+------+-----------+-----------------------+
| user | host | plugin |
+------+-----------+-----------------------+
| root | localhost | mysql_native_password |
+------+-----------+-----------------------+

到此,MySQL 8.0 的安装和配置就搞好了。