麒麟系统KylinOS安装MySQL8(Kylin Linux release 3.3.1703)
- 查看系统版本
查看Linux 内核的版本信息cat /proc/version
[root@kylinOS ~]# cat /proc/version
Linux version 3.10.0-514.ky3.kb3.x86_64 (mockbuild@kojibuilder101.kylinos.com.cn) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Thu Dec 29 21:29:54 EST 2016
查看Kylin系统信息 cat /etc/kylin-release
[root@kylinOS ~]# cat /etc/kylin-release
Kylin Linux release 3.3.1703 (Core)
- 下载对应MySQL版本
(1)访问官网:https://dev.mysql.com/downloads/mysql/ (2)选择版本,如图:社区版MySQL 8.0.36可与Kylin Linux release 3.3.1703兼容,Kylin 基于CentOS发展而来,以选择Red Hat版本即可,这里使用的是Red Hat Enterprise Linux / Oracle Linux - 安装MySQL
(1)上传到服务器指定目录,使用命令解压
tar xvf mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar
[root@kylinOS home]# tar xvf mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.0.36-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm
mysql-community-common-8.0.36-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.36-1.el7.x86_64.rpm
mysql-community-devel-8.0.36-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.36-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm
mysql-community-libs-8.0.36-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.36-1.el7.x86_64.rpm
mysql-community-server-8.0.36-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.36-1.el7.x86_64.rpm
mysql-community-test-8.0.36-1.el7.x86_64.rpm
(2)使用命令rpm -ivh
安装以下必选组件即可,注意必须按照先后顺序安装,如下
安装列表
rpm -ivh mysql-community-common-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.36-1.el7.x86_64.rpm
安装记录
[root@kylinOS home]# rpm -ivh mysql-community-common-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-common-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中... ################################# [100%]
软件包 mysql-community-common-8.0.36-1.el7.x86_64 已经安装
[root@kylinOS home]# rpm -ivh mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中... ################################# [100%]
软件包 mysql-community-client-plugins-8.0.36-1.el7.x86_64 已经安装
[root@kylinOS home]# rpm -ivh mysql-community-libs-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-libs-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中... ################################# [100%]
软件包 mysql-community-libs-8.0.36-1.el7.x86_64 已经安装
[root@kylinOS home]# rpm -ivh mysql-community-client-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-client-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中... ################################# [100%]
软件包 mysql-community-client-8.0.36-1.el7.x86_64 已经安装
[root@kylinOS home]# rpm -ivh mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中... ################################# [100%]
软件包 mysql-community-icu-data-files-8.0.36-1.el7.x86_64 已经安装
[root@kylinOS home]# rpm -ivh mysql-community-server-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-server-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中... ################################# [100%]
软件包 mysql-community-server-8.0.36-1.el7.x86_64 已经安装
[root@kylinOS home]# rpm -ivh mysql-community-devel-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-devel-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中... ################################# [100%]
软件包 mysql-community-devel-8.0.36-1.el7.x86_64 已经安装
- 修改配置
(1)添加mysql用户启动,安装mysql中已自动创建该用户
(2)修改配置
a.修改配置文件权限:chmod 644 /etc/my.cnf
b.配置文件
# 有关如何更改设置的建议,请参阅
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
# 设置读取缓存大小
innodb_buffer_pool_size = 4G
#调整排序缓存大小
sort_buffer_size = 512M
#临时表缓存大小
read_rnd_buffer_size = 256M
#线程缓存大小
thread_cache_size = 64
#
# 删除前导 # 并设置为最重要数据的 RAM 量
# 在MySQL中缓存。从专用服务器总 RAM 的 70% 开始,否则为 10%。
# innodb_buffer_pool_size = 128M
#
# 删除前导“#”以禁用二进制日志记录
# 二进制日志记录捕获备份之间的更改,并通过以下方式启用
# 违约。它的默认设置为 log_bin=binlog
# disable_log_bin
#
# 删除前导 # 以设置主要用于报表服务器的选项。
# 对于事务和快速的 SELECT,服务器默认值更快。
# 根据需要调整大小,进行实验以找到最佳值。
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# 删除前导 # 以恢复为default_authentication_plugin的先前值,
# 这将增加与旧客户端的兼容性。有关背景信息,请参阅:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 打开跳过权限检查,以方便修改密码
# skip-grant-tables
# 开启远程访问连接
bind-address=0.0.0.0
- 启动MySQL
(1)通过mysql用户指定配置文件启动
su -s /bin/bash mysql -c "/usr/sbin/mysqld --defaults-file=/etc/my.cnf"
[root@kylinOS home]# su -s /bin/bash mysql -c "/usr/sbin/mysqld --defaults-file=/etc/my.cnf"
2024-03-15T01:34:09.992372Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.36) starting as process 14995
2024-03-15T01:34:10.005891Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-03-15T01:34:16.356788Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
(2)使用root用户启用 systemctl start mysqld
注意:修改配置文件权限:chmod 644 /etc/my.cnf
,否则会在用mysql用户启动出现以下警告:
mysqld: [Warning] World-writable config file '/etc/my.cnf' is ignored.
这个警告是因为 /etc/my.cnf 配置文件的权限设置为world-writable,这是一个安全隐患。应修改这个文件的权限,使其只能被所有者和所属组的用户读取和写入,否则该配置文件始终将被忽略。
- 连接MySQL
跳过密码验证
skip-grant-tables
命令连接MySQL
mysql -uroot -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
关闭密码验证重启MySQL
- 常见问题
问题:安装过程出现的依赖缺失:
[root@kylinOS home]# rpm -ivh mysql-community-server-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-server-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
错误:依赖检测失败:
libcrypto.so.10(OPENSSL_1.0.2)(64bit) 被 mysql-community-server-8.0.36-1.el7.x86_64 需要
解决:访问地址libcrypto.so.10(OPENSSL_1.0.2)(64bit)下载对应的版本后使用命令 rpm -ivh
执行安装即可
[root@kylinOS home]# rpm -ivh openssl-libs-1.0.2k-26.el7_9.x86_64.rpm
警告:openssl-libs-1.0.2k-26.el7_9.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中... ################################# [100%]
软件包 openssl-libs-1:1.0.2k-26.el7_9.x86_64 已经安装
问题:MySQL 8.0 解决:ERROR 1819 密码策略修改