Ubuntu 23系统中MySQL Server 8.0无法启动求助
MySQL服务启动失败:被OOM Killer终止
问题场景
通过以下命令安装MySQL:
sudo apt install MySQL-Server
安装完成后服务无法正常启动,一直处于激活(自动重启)状态。
执行命令及输出
执行以下命令排查服务状态:
systemctl status mysql.service journalctl -xeu mysql.service
输出内容如下:
mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled) Active: activating (auto-restart) (Result: oom-kill) since Sat 2023-07-29 08:01:47 PDT; 227ms ago Process: 2378 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Process: 2386 ExecStart=/usr/sbin/mysqld (code=killed, signal=KILL) Main PID: 2386 (code=killed, signal=KILL) Status: "Server startup in progress" CPU: 2.649s Jul 29 08:01:47 ubuntu systemd[1]: mysql.service: A process of this unit has been killed by the OOM killer. Jul 29 08:01:47 ubuntu systemd[1]: mysql.service: Main process exited, code=killed, status=9/KILL Jul 29 08:01:47 ubuntu systemd[1]: mysql.service: Failed with result 'oom-kill'. Jul 29 08:01:47 ubuntu systemd[1]: Failed to start mysql.service - MySQL Community Server. Jul 29 08:01:47 ubuntu systemd[1]: mysql.service: Consumed 2.649s CPU time. Jul 29 08:01:47 ubuntu systemd[1]: mysql.service: Scheduled restart job, restart counter is at 71. Jul 29 08:01:47 ubuntu systemd[1]: Stopped mysql.service - MySQL Community Server. Jul 29 08:01:47 ubuntu systemd[1]: mysql.service: Consumed 2.649s CPU time. Jul 29 08:01:47 ubuntu systemd[1]: Starting mysql.service - MySQL Community Server... :~$ journalctl -xeu mysql.service Jul 29 08:02:43 ubuntu systemd[1]: mysql.service: Scheduled restart job, restart counter is at 76. ░░ Subject: Automatic restarting of a unit has been scheduled ░░ Defined-By: systemd ░░ Support: http://www.ubuntu.com/support ░░ ░░ Automatic restarting of the unit mysql.service has been scheduled, as the result for ░░ the configured Restart= setting for the unit. Jul 29 08:02:43 ubuntu systemd[1]: Stopped mysql.service - MySQL Community Server. ░░ Subject: A stop job for unit mysql.service has finished ░░ Defined-By: systemd ░░ Support: http://www.ubuntu.com/support ░░ ░░ A stop job for unit mysql.service has finished. ░░ ░░ The job identifier is 8529 and the job result is done. Jul 29 08:02:43 ubuntu systemd[1]: mysql.service: Consumed 2.685s CPU time. ░░ Subject: Resources consumed by unit runtime ░░ Defined-By: systemd ░░ Support: http://www.ubuntu.com/support ░░ ░░ The unit mysql.service completed and consumed the indicated resources. Jul 29 08:02:43 ubuntu systemd[1]: Starting mysql.service - MySQL Community Server... ░░ Subject: A start job for unit mysql.service has begun execution ░░ Defined-By: systemd ░░ Support: http://www.ubuntu.com/support ░░ ░░ A start job for unit mysql.service has begun execution. ░░ ░░ The job identifier is 8529.
已尝试操作
多次执行purge、clean、autoremove和update命令,问题仍未解决。
解决方法
从日志可明确:MySQL进程被**OOM Killer(内存不足终止器)**杀死,核心原因是系统可用内存不足以支撑MySQL启动,按以下步骤处理:
临时释放内存
用htop查看高内存占用进程,手动关闭不需要的进程;或执行以下命令清理缓存:sudo sync && sudo sysctl -w vm.drop_caches=3调整MySQL内存配置
编辑MySQL配置文件(通常路径为/etc/mysql/mysql.conf.d/mysqld.cnf),降低内存相关参数(以1G内存系统为例):sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf修改以下参数:
innodb_buffer_pool_size = 128M key_buffer_size = 32M max_connections = 50 query_cache_size = 0保存后重启服务:
sudo systemctl restart mysql长期解决方案
若为虚拟机/云服务器,升级实例内存;若为物理机,加装内存条。
内容的提问来源于stack exchange,提问作者Gunyen
相关产品推荐
相关产品推荐

