Ok so, after typing all that up and going through a hundred or more forum posts, I was actually still having the same problem of MySQL-Server hanging when I was trying to install.
Fortunately, I documented everything as I found potential solutions, and referenced all of it to fix my problem.
Again, my symptoms were:
- apt (advanced packaging tool) could not complete fresh install of MySQL. It would hang on the line: Setting up MySQL-Server-5.1
- Because apt would freeze, I would have to force close, which would give me /var/lib/dpkg/lock issues, aka error: "Could not get lock /var/lib/apt/lists/lock"
- Any attempt to purge/remove MySQL would end erroneously, either because of missing dependencies, or other errors.
- If I was able to trick MySQL into kind of finishing install, I would receive the error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
To solve these problems:
Problem #1: apt (advanced packaging tool) could not complete fresh install of MySQL. It would hang on the line: Setting up MySQL-Server-5.1
Solution: I found that if I went into a new terminal tab while that was "setting up" and typed in:
service mysql stop
It allowed the install to complete.
Problem #2: Because apt would freeze, I would have to force close, which would give me /var/lib/dpkg/lock issues, aka error: "Could not get lock /var/lib/apt/lists/lock"
Solution: First command I would type in:
sudo fuser -vki /var/lib/dpkg/lock
sudo fuser -vvv /var/lib/dpkg/lock
cat /etc/lsb-release
uname -a
sudo rm /var/lib/apt/lists/lock
sudo cp -arf /var/lib/dpkg /var/lib/dpkg.backup
sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status
sudo cp /var/lib/dpkg/available-old /var/lib/dpkg/available
sudo rm -rf /var/lib/dpkg/updates/*
sudo rm -rf /var/lib/apt/lists
sudo rm /var/cache/apt/*.bin
sudo mkdir /var/lib/apt/lists
sudo mkdir /var/lib/apt/lists/partial
LANG=C;sudo apt-get clean
LANG=C;sudo apt-get autoclean
LANG=C;sudo apt-get --purge autoremove
LANG=C;sudo apt-get update -o APT::Cache-Limit=25165824
sudo dpkg --configure -a
sudo dpkg --clear-avail
LANG=C;sudo apt-get -f install
LANG=C;sudo apt-get --fix-missing install
LANG=C;sudo apt-get update -o APT::Cache-Limit=25165824 && sudo apt-get dist-upgrade
This cleared up my apt-get/dpkg issues, including partially installed packages.
Problem #3: Any attempt to purge/remove MySQL would end erroneously, either because of missing dependencies, or other errors.
Solution: Perform the previous step before you go here.
First I kill any mysql process, check:
ps -e | grep mysql
And make sure mysql/mysqld is not running. Then:
apt-get --purge autoremove mysql-common
apt-get --purge autoremove mysql-server
In addition to this, I deleted /var/lib/mysql, because that appeared to contain some user information and configuration files that were overlapping into the "fresh installs". I did a locate mysql and looked around at some of the folders and deleted any that I thought contained configuration files or user info.
Problem #4: If I was able to trick MySQL into kind of finishing install, I would receive the error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Solution: As long as you delete /var/lib/mysql, purge all MySQL packages and perform a fresh install, you should no longer receive this error. Just make sure your mysqld (MySQL daemon) service is running and your /etc/my.cnf file is pointing to the right location. But, since you theoretically did a fresh install, the default my.cnf settings should be correct and working, they were for me.
Good luck.