麒麟系统V10安装Mysql8.0

麒麟系统V10安装Mysql8.0

𝓓𝓸𝓷 Lv6

麒麟系统安装Mysql8.0

一、查看麒麟系统版本

确认系统架构是arm还是x86平台

1
2
3
4
5
6
7
# cat /etc/os-release 
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Sword)"
ID="kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Sword)"
ANSI_COLOR="0;31"

二、关闭防火墙

1
2
3
systemctl stop firewalld  
systemctl disable firewalld
systemctl status firewalld

三、关闭selinux

1
2
3
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux  
setenforce 0
getenforce

四、关闭透明大页

参考文章: 麒麟V10关闭透明大页

五、卸载旧的版本及配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
for i in $(rpm -qa|grep mysql);do rpm -e $i --nodeps;done

rm -rf /var/lib/mysql
rm -rf /etc/my.cnf
rm -rf /usr/share/mysql
rm -rf /etc/my.cnf.d
rm -rf /etc/mysql

---卸载mariadb:
rpm -qa |grep mariadb
yum remove mariadb-libs-5.5.68-1.el7.x86_64

---删除mysql用户
userdel -r mysql

六、安装操作系统依赖包

1
2
3
4
yum -y install libaio libaio-devel

# Oracle Linux 8 / Red Hat 8 (EL8): CentOS 8 mysql: error while loading shared libraries: libncurses.so.5
yum install ncurses ncurses-compat-libs -y

七、下载Mysql

1.查看glibc版本
1
2
# ldd --version|head -1
ldd (GNU libc) 2.28
2.下载对应的Mysql版本

image-20260826170748352

八、创建用户及目录

1
2
3
# 创建mysql用户(无登录权限)
useradd -s /sbin/nologin -M mysql
mkdir -p /data/mysql

九、解压

1
# tar xvf mysql-8.0.45-linux-glibc2.28-x86_64.tar.xz -C /usr/local

十、创建软链接

1
2
3
# cd /usr/local/
# ln -s mysql-8.0.45-linux-glibc2.28-x86_64 mysql
# chown -R root.root mysql/*

十一、添加环境变量

1
2
3
4
5
6
# cat >> /etc/profile <<EOF

export PATH=$PATH:/usr/local/mysql/bin
EOF

# source /etc/profile

十二、创建my.cnf配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql
socket = /tmp/mysql.sock
pid-file = /data/mysql/mysqld.pid
user = mysql
port = 3306
server-id = 1
default-time-zone = +08:00
lower_case_table_names = 1


####character-set###
character-set-server = utf8mb4

####log####
log_bin = /data/mysql/mysql-bin
binlog_format = ROW
binlog_expire_logs_seconds = 604800
max_binlog_size = 1G
log-error = /data/mysql/error.log

####connections####
max_connections = 1500
wait_timeout = 3600
interactive_timeout = 3600
max_user_connections = 200
# default_authentication_plugin = mysql_native_password
skip-name-resolve = ON

####innodb####
innodb_buffer_pool_size = 20G
innodb_redo_log_capacity = 4G


[client]
default-character-set = utf8mb4
socket = /tmp/mysql.sock


[mysql]
prompt="\\u@\\h [\\d]-> "
default-character-set = utf8mb4

十三、初始化数据

1
2
3
4
5
6
7
8
9
# mysqld --initialize --user=mysql --datadir=/data/mysql

# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

# mysqld --initialize --user=mysql --datadir=/data/mysql
2026-08-26T09:51:19.415546Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.45-linux-glibc2.28-x86_64/bin/mysqld (mysqld 8.0.45) initializing of server in progress as process 3002
2026-08-26T09:51:19.482944Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-08-26T09:51:19.858676Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-08-26T09:51:23.736961Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: klM_e$XtH3e8

十四、创建启动/关闭数据库服务

启动mysql可以采用sys-v或systemd两种方式启动

1.sys-v方式启动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
---创建启动脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

---启动Mysql
# /etc/init.d/mysql start
Starting MySQL.. SUCCESS

---关闭Mysql
# /etc/init.d/mysql stop
Shutting down MySQL.. SUCCESS!



# service mysql start
# service mysql stop



# mysqld_safe --user=mysql &
2.systemd方式启动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---创建启动脚本
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/init.d/mysql

---配置mysql开机自动启动
# chkconfig mysql on
# systemctl enable mysql

---启动与关闭mysql
# systemctl start mysql
# systemctl status mysql
# systemctl stop mysql


或者参考手工配置systemd启动服务:

# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld \
--datadir=/data/mysql \
--basedir=/usr/local/mysql \
--user=mysql \
--log-error=/var/log/mysql/error.log \
--pid-file=/tmp/mysql/mysqld.pid \
--socket=/tmp/mysql/mysql.sock \
--tmpdir=/tmp/mysql \
--port=3306
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1

# 重新加载systemd配置
systemctl daemon-reload
# 设置开机自启
systemctl enable mysqld
# 启动MySQL服务
systemctl start mysqld
# 查看服务状态(显示active (running)则启动成功)
systemctl status mysqld

或参考:
vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
Type=notify
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Start main service
ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
# Set enviroment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false

十五、启动Mysql

1
2
3
# /etc/init.d/mysql start

# systemctl start mysql
  • Title: 麒麟系统V10安装Mysql8.0
  • Author: 𝓓𝓸𝓷
  • Created at : 2026-08-26 16:42:58
  • Updated at : 2026-08-27 14:02:47
  • Link: https://www.zhangdong.me/install-mysql-on-kylin-operating-system.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论