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的配置文件来减少它的内存消耗:
- 先停止当前反复重启的MySQL服务:
sudo systemctl stop mysql - 备份默认配置文件(避免改错无法恢复):
sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak - 编辑配置文件:
sudo nano /etc/mysql/my.cnf - 在
[mysqld]区块下添加或修改以下参数(这些参数会大幅降低MySQL的内存占用):innodb_buffer_pool_size = 128M key_buffer_size = 16M max_connections = 50 query_cache_size = 0 query_cache_type = 0 - 按
Ctrl+O保存,Ctrl+X退出编辑器 - 重新配置MySQL安装包:
sudo dpkg --configure -a - 启动MySQL服务并检查状态:
sudo systemctl start mysql sudo systemctl status mysql
三、如果之前卸载不彻底,清理残留后重新安装
如果之前的卸载操作没清理干净,也可能导致后续安装出问题,可以彻底清理后再重装:
- 彻底卸载所有MySQL相关包:
sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-* - 删除残留的配置和数据文件:
sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql - 更新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
相关产品推荐
相关产品推荐

