Unable to set password for the mysql "root" user

Same root password setting problem here, mine possibly caused by an unsuccessful manual installation of mysql server 5.6 previously. A thorough mysql uninstallation is no easy task. I purged/reinstalled for hours then finally solved it with

sudo dpkg --purge mysql-client-core-5.5 # or alternative version
sudo dpkg --purge mysql-client
sudo dpkg --purge mysql-server-core-5.5 # or alternative version
sudo dpkg --purge mysql-common

Basically I just type

sudo dpkg --purge mysql # followed by two tabs

Then --purge any packages the terminal auto-completes. Purge mysql-common at last because of some dependency problems.

Use above dpkg commands in addition to

sudo apt-get --purge remove mysql-server
sudo apt-get --purge remove mysql-client
sudo apt-get --purge remove mysql-common
sudo apt-get autoremove
sudo apt-get autoclean

Also I tried Greq's method

sudo rm -rf /etc/mysql

Remove the mysql folder from /var/lib

sudo rm -rf /var/lib/mysql/

At this point, to make sure mysql is fully removed, check with

which mysql
mysql --version

The first one should return no output instead of a folder. The second should return mysql is not installed instead of a version number. Otherwise the removal is still incomplete.

The significance of dpkg --purge is, when using apt-get alone, which mysql and mysql --version behave like mysql is still there.

Before reinstallation, reconfigure dpkg and update

sudo dpkg --configure -a
sudo apt-get update

Problem resolved finally. Hope it will be helpful for other people.


You need to completely remove mysql. Believe me, I tryied. dpkg will not do this alone.

See

https://stackoverflow.com/questions/10853004/removing-mysql-5-5-completely

If you are in a hurry

sudo service mysql stop  #or mysqld
sudo killall -9 mysql
sudo killall -9 mysqld
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo apt-get purge mysql-server-core-5.5
sudo apt-get purge mysql-client-core-5.5

I think the reason is that mysql is not able to access your /tmp/ directory, as it says in the line

mysqld: Can't create/write to file '/tmp/ibNuz7q0' (Errcode: 13)

Run the following commands in a terminal:

sudo su
chown root:root /tmp
chmod 1777 /tmp
/usr/sbin/mysqld &

Explanation:

  • sudo su : To run the following commands as root.
  • chown root:root /tmp : Make the user root of root group the owner of /tmp.
  • chmod 1777 /tmp : Change the permissions of /tmp so that it is accessable to all the users and only the owner or the root can delete the files in that directory. (More on file permissions here)
  • /usr/sbin/mysqld & : Start the mysqld daemon.