麒麟系统安装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版本
八、创建用户及目录 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
十二、初始化数据 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: 1;Mhti&ad3uw
十三、创建启动/关闭数据库服务
启动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
十三、创建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 44 # 创建配置文件 vim /etc/my.cnf # 粘贴以下配置(生产级优化,按需调整) [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 skip-name-resolve # 禁用DNS解析,提升连接速度 skip-external-locking # 禁用外部锁 # 字符集(适配中文) character-set-server = utf8mb4 collation-server = utf8mb4_general_ci init_connect = 'SET NAMES utf8mb4' # 日志配置 log-error = /data/mysql/error.log # 错误日志 slow_query_log = 1 # 开启慢查询日志 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 2 # 慢查询阈值(2秒) log_queries_not_using_indexes = 1 # 记录未使用索引的查询 # 性能优化(根据服务器配置调整) max_connections = 1000 # 最大连接数 max_connect_errors = 1000000 # 最大连接错误数 innodb_buffer_pool_size = 2G # 内存的50%-70%(示例:8G内存设4G) innodb_log_file_size = 512M # 日志文件大小 innodb_log_buffer_size = 64M innodb_flush_log_at_trx_commit = 1 # 事务安全(生产建议1) tmp_table_size = 64M max_heap_table_size = 64M query_cache_type = 0 # 8.0已废弃,关闭 query_cache_size = 0 [client] socket = /tmp/mysql/mysql.sock default-character-set = utf8mb4 [mysql] prompt="\\u@\\h [\\d]>" # 美化命令行提示符 default-character-set = utf8mb4