How to Fix MySQL Server Installation Failure on Ubuntu: “dpkg error processing mysql-server-5.1”


3 views

When attempting to install or configure mysql-server on Ubuntu (particularly older versions like 9.10), you might encounter the notorious dpkg error during package configuration. The key symptoms are:

* Starting MySQL database server mysqld [fail]
invoke-rc.d: initscript mysql, action "start" failed
dpkg: error processing mysql-server-5.1 (--configure)
subprocess installed post-installation script returned error exit status 1

Before diving into solutions, let's gather some system information:

# Check MySQL error logs
sudo tail -n 50 /var/log/mysql/error.log

# Verify disk space
df -h

# Check existing MySQL processes
ps aux | grep mysql

1. Clean Up Previous Install Attempts

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql

2. Fix Broken Dependencies

sudo apt-get install -f
sudo dpkg --configure -a

3. Manual Configuration (When Automatic Fails)

If the automatic configuration fails, try configuring manually:

sudo dpkg --configure mysql-server-5.1
sudo dpkg --configure mysql-server

4. Alternative Installation Method

For stubborn cases, download the .deb package directly:

wget http://archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.1/mysql-server-5.1_5.1.37-1ubuntu5.4_amd64.deb
sudo dpkg -i mysql-server-5.1_5.1.37-1ubuntu5.4_amd64.deb
sudo apt-get install -f

Checking Configuration Files

Sometimes conflicts in /etc/mysql/my.cnf can cause startup failures:

sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.backup
sudo cp /usr/share/mysql/my-medium.cnf /etc/mysql/my.cnf

MySQL User and Permissions

sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 755 /var/lib/mysql

Manual Service Start Attempt

sudo mysqld_safe --skip-grant-tables &

For Ubuntu 9.10 specifically (which reached end-of-life years ago), consider these precautions:

# Always update package lists first
sudo apt-get update

# Install dependencies explicitly
sudo apt-get install libaio1 libdbd-mysql-perl libdbi-perl libnet-daemon-perl libplrpc-perl

As a last resort, completely purge all MySQL components and reinstall:

sudo apt-get purge mysql*
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get update
sudo apt-get install mysql-server

When attempting to install mysql-server on Ubuntu 9.10 (Karmic Koala), you might encounter this frustrating situation where the package appears installed but fails to configure properly. The key symptoms are:

Setting up mysql-server-5.1 (5.1.37-1ubuntu5.4) ...
* Stopping MySQL database server 
    Mysqld    [ OK ]
* Starting MySQL database server 
mysqld [fail]

Before attempting fixes, let's gather more information about the system state:

# Check installed MySQL packages
dpkg -l | grep mysql

# View configuration errors
sudo dpkg --configure -a

# Examine MySQL error logs
tail -n 50 /var/log/mysql/error.log

Method 1: Complete Reinstallation with Purge

First, completely remove all MySQL components and reinstall:

# Stop MySQL if running
sudo service mysql stop

# Remove all MySQL packages
sudo apt-get remove --purge mysql-server mysql-client mysql-common

# Clean up residual files
sudo rm -rf /etc/mysql /var/lib/mysql

# Autoremove dependencies
sudo apt-get autoremove

# Reinstall fresh
sudo apt-get install mysql-server

Method 2: Manual Configuration Recovery

If the above fails, try manually completing the configuration:

# Force reconfigure packages
sudo dpkg --configure -a

# Specifically configure MySQL packages
sudo dpkg --configure mysql-server-5.1
sudo dpkg --configure mysql-server

Method 3: Fixing File Permissions

Permission issues often cause startup failures:

# Ensure proper ownership
sudo chown -R mysql:mysql /var/lib/mysql

# Repair existing database files
sudo mysql_install_db --user=mysql --ldata=/var/lib/mysql

For persistent issues, check these system-level factors:

# Verify available disk space
df -h

# Check memory availability
free -m

# Examine system logs
journalctl -xe

For very old Ubuntu versions, consider switching to MariaDB:

# Remove existing MySQL
sudo apt-get remove --purge mysql*

# Install MariaDB
sudo apt-get install mariadb-server

After successful installation, verify the service status:

# Check service status
sudo systemctl status mysql

# Test client connection
mysql -u root -p -e "SHOW DATABASES;"