Reinstall MySQL on Ubuntu on a broken previous installation

20. June 2016 Mysql 0

Scenario:

Mysql was removed by a user without knowing what he was doing. He tried to install it again and not sure what all steps he followed.

If you try to install you will face below problem

  1. you cannot set MySQL root password
  2. MySQL will not be started after installation
  3. you will see MySQL dependencies errors

When I tried to install the packages I got below error message.

MySQL: Can’t create/write to file ‘/tmp********************

dpkg: error processing package mysql-server-5.5 (–configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.5; however:
Package mysql-server-5.5 is not configured yet.

start: Job failed to start
invoke-rc.d: initscript mysql, action “start” failed.
dpkg: error processing package mysql-server-5.5 (–configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.5; however:
Package mysql-server-5.5 is not configured yet.

dpkg: error processing package mysql-server (–configure):
dependency problems – leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
mysql-server-5.5
mysql-server

Solution

1)  Make sure /tmp folder has correct permission (1777 )

2) Remove MySQL and clean up folders

sudo apt-get remove –purge mysql-server mysql-client mysql-common mysql-server-5.5 mysql-client-5.5 mysql-server-core-5.5 mysql-client-core-5.5
sudo apt-get autoremove
sudo apt-get autoclean`
sudo rm -rf /var/lib/mysql /etc/mysql  ( you should take a copy of this folder if you have any database on the server )
sudo deluser mysql

3) Install MySQL Now

sudo apt-get install mysql-server-5.5
sudo apt-get install mysql-server