MySQL Server Installation Hangs at Key Buffer Renaming Step on Ubuntu 16.04: Debug Guide


2 views

html

When running sudo apt-get install mysql-server on Ubuntu 16.04, many developers encounter the installation freezing at:

Renaming removed key_buffer and myisam-recover options (if present)

This typically occurs after setting the root password but before completing the configuration steps.

The hang happens during MySQL's configuration phase where it attempts to migrate old configuration parameters. Ubuntu 16.04's default MySQL packages (version 5.7) have known issues with certain system configurations.

Method 1: Manual Configuration First

sudo apt-get update
sudo apt-get install mysql-server-5.7 mysql-client-5.7 --fix-missing
sudo mysql_secure_installation

Method 2: Clean Reinstall Approach

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

Check system logs during installation:

journalctl -xe | grep mysql

Common findings include:

  • Permission issues in /var/lib/mysql
  • AppArmor blocking operations
  • Leftover configuration from previous installations

For systems with existing MySQL data:

sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo systemctl start mysql

When AppArmor is the culprit:

sudo aa-complain /usr/sbin/mysqld
sudo systemctl restart apparmor

If package installation continues to fail, consider:

  1. Using Docker:
    docker run --name mysql16 -e MYSQL_ROOT_PASSWORD=yourpass -d mysql:5.7
    
  2. Manual .deb package installation

After successful installation, verify with:

mysqladmin -u root -p version

And check the error log:

sudo tail -100 /var/log/mysql/error.log

When running the standard MySQL installation command:

sudo apt-get install mysql-server

The process consistently gets stuck at this specific point:

Renaming removed key_buffer and myisam-recover options (if present)

The issue primarily stems from systemd service management conflicts with older MySQL configurations. Here's what's happening behind the scenes:

  • The package tries to migrate old my.cnf settings
  • Systemd fails to properly handshake with mysqld
  • AppArmor profile conflicts may occur

First, completely purge existing installations:

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

Create temporary configuration override:

echo "[mysqld]
skip-grant-tables" | sudo tee /etc/mysql/conf.d/temp.cnf

Method 1: Use the official MySQL repo

wget https://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb
sudo apt-get update
sudo apt-get install mysql-server

Method 2: Install MariaDB instead (drop-in replacement)

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386] http://mirrors.accretive-networks.net/mariadb/repo/10.1/ubuntu xenial main'
sudo apt-get update
sudo apt-get install mariadb-server

After successful installation, verify the service status:

sudo systemctl status mysql
# Or for MariaDB:
sudo systemctl status mariadb

Secure your installation with:

sudo mysql_secure_installation

Check the MySQL error log in real-time:

sudo tail -f /var/log/mysql/error.log

Examine systemd journal for clues:

journalctl -xe -u mysql.service