You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04 LTS中MySQL安装失败,服务因OOM Killer被终止

Ubuntu 22.04 LTS中MySQL安装失败,服务因OOM Killer被终止

看起来你遇到的核心问题是MySQL服务启动时被系统的OOM Killer(内存不足终止器)强制终止了,这在资源有限的VirtualBox虚拟机里特别常见——MySQL 8.0默认的内存配置对小内存虚拟机来说压力太大。咱们一步步来解决这个问题:

一、先确认并提升虚拟机内存(最直接的解决方案)

你的错误日志里明确显示A process of this unit has been killed by the OOM killer,说明虚拟机分配的内存不足以支撑MySQL启动:

  • 关闭你的Ubuntu虚拟机
  • 打开VirtualBox,找到对应的虚拟机,点击「设置」→「系统」→「主板」
  • 把内存分配调高到至少2GB(如果主机资源允许,推荐4GB)
  • 启动虚拟机后,重新尝试配置MySQL:
    sudo dpkg --configure -a
    

二、如果暂时没法加内存,修改MySQL配置降低内存占用

如果主机内存紧张,没法给虚拟机加太多资源,可以通过修改MySQL的配置文件来减少它的内存消耗:

  1. 先停止当前反复重启的MySQL服务:
    sudo systemctl stop mysql
    
  2. 备份默认配置文件(避免改错无法恢复):
    sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
    
  3. 编辑配置文件:
    sudo nano /etc/mysql/my.cnf
    
  4. 在[mysqld]区块下添加或修改以下参数(这些参数会大幅降低MySQL的内存占用):
    innodb_buffer_pool_size = 128M
    key_buffer_size = 16M
    max_connections = 50
    query_cache_size = 0
    query_cache_type = 0
    
  5. 按Ctrl+O保存,Ctrl+X退出编辑器
  6. 重新配置MySQL安装包:
    sudo dpkg --configure -a
    
  7. 启动MySQL服务并检查状态:
    sudo systemctl start mysql
    sudo systemctl status mysql
    

三、如果之前卸载不彻底,清理残留后重新安装

如果之前的卸载操作没清理干净,也可能导致后续安装出问题,可以彻底清理后再重装:

  1. 彻底卸载所有MySQL相关包:
    sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
    
  2. 删除残留的配置和数据文件:
    sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql
    
  3. 更新apt缓存并重新安装:
    sudo apt update
    sudo apt install mysql-server
    

附上你提供的错误日志供参考:

● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: oom-kill) since Fri 2023-02-17 09:55:40 UTC; 55ms ago
Process: 3089 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Process: 3097 ExecStart=/usr/sbin/mysqld (code=killed, signal=KILL)
Main PID: 3097 (code=killed, signal=KILL)
Status: "Server startup in progress"
CPU: 1.028s

Feb 17 09:55:40 vagrant-ubuntu-trusty-64 systemd[1]: mysql.service: A process of this unit has been killed by the OOM killer.
Feb 17 09:55:40 vagrant-ubuntu-trusty-64 systemd[1]: mysql.service: Main process exited, code=killed, status=9/KILL
Feb 17 09:55:40 vagrant-ubuntu-trusty-64 systemd[1]: mysql.service: Failed with result 'oom-kill'.
Feb 17 09:55:40 vagrant-ubuntu-trusty-64 systemd[1]: Failed to start MySQL Community Server.
Feb 17 09:55:40 vagrant-ubuntu-trusty-64 systemd[1]: mysql.service: Consumed 1.028s CPU time.

dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
mysql-server-8.0

备注:内容来源于stack exchange,提问作者Habtamu S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 11:58:00