Question

Getting Error while reinstalling MYSQL

I had my disk space full due to which I couldn’t delete binary logs using sql command. So, I took a backup deleted some bin files manually using SFTP. After this mysql start messing up, so I uninstalled and installed again but it isn’t working.

I ran following code to uninstall:

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

And for installing I followed this tutorial:

https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04

And now I getting an error

“Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)”

Please help me out

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
May 12, 2022
Accepted Answer

Hi there,

I could suggest following the steps from this answer here on how to completely uninstall MySQL:

https://www.digitalocean.com/community/questions/completely-uninstall-mysql-server

Let me know how it goes after that.

And if you are still seeing the error, can you check the MySQL status with:

sudo systemctl status mysql

And also check your MySQL error log and share the output here?

Best,

Bobby

So, I tried uninstalling and reinstalling and I’m getting this error

root@popular-quizz-0:~# sudo systemctl stop mysql

root@popular-quizz-0:~# sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'mysql-server-core-5.0' for glob 'mysql-server-core-*'
Note, selecting 'mysql-server-core-5.1' for glob 'mysql-server-core-*'
Note, selecting 'mysql-server-core-5.5' for glob 'mysql-server-core-*'
Note, selecting 'mysql-server-core-5.6' for glob 'mysql-server-core-*'
Note, selecting 'mysql-server-core-5.7' for glob 'mysql-server-core-*'
Note, selecting 'mysql-server-core-8.0' for glob 'mysql-server-core-*'
Package 'mysql-server-core-5.7' is not installed, so not removed
Package 'mysql-server-core-5.5' is not installed, so not removed
Package 'mysql-server-core-5.6' is not installed, so not removed
Package 'mysql-server-core-5.0' is not installed, so not removed
Package 'mysql-server-core-5.1' is not installed, so not removed
Note, selecting 'mysql-client-core-5.0' for glob 'mysql-client-core-*'
Note, selecting 'mysql-client-core-5.1' for glob 'mysql-client-core-*'
Note, selecting 'mysql-client-core-5.5' for glob 'mysql-client-core-*'
Note, selecting 'mysql-client-core-5.6' for glob 'mysql-client-core-*'
Note, selecting 'mysql-client-core-5.7' for glob 'mysql-client-core-*'
Note, selecting 'mysql-client-core-8.0' for glob 'mysql-client-core-*'
Package 'mysql-client-core-5.7' is not installed, so not removed
Package 'mysql-client-core-5.5' is not installed, so not removed
Package 'mysql-client-core-5.6' is not installed, so not removed
Package 'mysql-client-core-5.0' is not installed, so not removed
Package 'mysql-client-core-5.1' is not installed, so not removed
Package 'mysql-client-core-8.0' is not installed, so not removed
Package 'mysql-server-core-8.0' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  libfwupdplugin1 libmecab2 linux-headers-5.4.0-105 linux-headers-5.4.0-105-generic linux-headers-5.4.0-107 linux-headers-5.4.0-107-generic linux-image-5.4.0-107-generic
  linux-modules-5.4.0-105-generic linux-modules-5.4.0-107-generic mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-community-client-core mysql-community-client-plugins
  mysql-community-server-core
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  mysql-client* mysql-common* mysql-community-client* mysql-community-server* mysql-server*
0 upgraded, 0 newly installed, 5 to remove and 3 not upgraded.
1 not fully installed or removed.
After this operation, 43.5 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 161033 files and directories currently installed.)
Removing mysql-server (8.0.26-1ubuntu20.04) ...
Removing mysql-community-server (8.0.26-1ubuntu20.04) ...
update-alternatives: warning: alternative /etc/mysql/my.cnf.fallback (part of link group my.cnf) doesn't exist; removing from list of alternatives
update-alternatives: warning: alternative /etc/mysql/mysql.cnf (part of link group my.cnf) doesn't exist; removing from list of alternatives
update-alternatives: warning: /etc/alternatives/my.cnf is dangling; it will be updated with best choice
Removing mysql-client (8.0.26-1ubuntu20.04) ...
Removing mysql-community-client (8.0.26-1ubuntu20.04) ...
Removing mysql-common (8.0.26-1ubuntu20.04) ...
Processing triggers for man-db (2.9.1-1) ...
(Reading database ... 160973 files and directories currently installed.)
Purging configuration files for mysql-community-client (8.0.26-1ubuntu20.04) ...
Purging configuration files for mysql-common (8.0.26-1ubuntu20.04) ...
update-alternatives: error: no alternatives for my.cnf
dpkg: error processing package mysql-common (--purge):
 installed mysql-common package post-removal script subprocess returned error exit status 2
Purging configuration files for mysql-community-server (8.0.26-1ubuntu20.04) ...
.
Errors were encountered while processing:
 mysql-common
E: Sub-process /usr/bin/dpkg returned an error code (1)

root@popular-quizz-0:~# sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql
root@popular-quizz-0:~# sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql
root@popular-quizz-0:~# sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  libfwupdplugin1 libmecab2 linux-headers-5.4.0-105 linux-headers-5.4.0-105-generic linux-headers-5.4.0-107 linux-headers-5.4.0-107-generic linux-image-5.4.0-107-generic
  linux-modules-5.4.0-105-generic linux-modules-5.4.0-107-generic mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-community-client-core mysql-community-client-plugins
  mysql-community-server-core
0 upgraded, 0 newly installed, 15 to remove and 3 not upgraded.
After this operation, 583 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 160942 files and directories currently installed.)
Removing libfwupdplugin1:amd64 (1.5.11-0ubuntu1~20.04.2) ...
Removing mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ...
update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Removing mecab-ipadic (2.7.0-20070801+main-2.1) ...
Removing mecab-utils (0.996-10build1) ...
Removing mysql-community-server-core (8.0.26-1ubuntu20.04) ...
Removing libmecab2:amd64 (0.996-10build1) ...
Removing linux-headers-5.4.0-105-generic (5.4.0-105.119) ...
Removing linux-headers-5.4.0-105 (5.4.0-105.119) ...
Removing linux-headers-5.4.0-107-generic (5.4.0-107.121) ...
Removing linux-headers-5.4.0-107 (5.4.0-107.121) ...
Removing linux-image-5.4.0-107-generic (5.4.0-107.121) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.4.0-107-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/50-cloudimg-settings.cfg'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-110-generic
Found initrd image: /boot/initrd.img-5.4.0-110-generic
Found linux image: /boot/vmlinuz-5.4.0-109-generic
Found initrd image: /boot/initrd.img-5.4.0-109-generic
done
Removing linux-modules-5.4.0-105-generic (5.4.0-105.119) ...
Removing linux-modules-5.4.0-107-generic (5.4.0-107.121) ...
Removing mysql-community-client-core (8.0.26-1ubuntu20.04) ...
Removing mysql-community-client-plugins (8.0.26-1ubuntu20.04) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...

root@popular-quizz-0:~# sudo apt autoclean
Reading package lists... Done
Building dependency tree       
Reading state information... Done



root@popular-quizz-0:~# sudo apt update

Get:1 http://repo.mysql.com/apt/ubuntu focal InRelease [12.9 kB]
Get:2 http://mirrors.digitalocean.com/ubuntu focal InRelease [265 kB]                                                                                                                       
Hit:3 http://mirrors.digitalocean.com/ubuntu focal-updates InRelease                                                                                                                        
Hit:4 https://repos.insights.digitalocean.com/apt/do-agent main InRelease                                                                                                                   
Hit:5 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease                                                                                                           
Hit:6 http://mirrors.digitalocean.com/ubuntu focal-backports InRelease                                                                                            
Err:1 http://repo.mysql.com/apt/ubuntu focal InRelease              
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29
Hit:7 http://ppa.launchpad.net/ondrej/php/ubuntu focal InRelease
Get:8 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Fetched 392 kB in 1s (575 kB/s)    
Reading package lists... Done
Building dependency tree       
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://repo.mysql.com/apt/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29
W: Failed to fetch http://repo.mysql.com/apt/ubuntu/dists/focal/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29
W: Some index files failed to download. They have been ignored, or old ones used instead.

root@popular-quizz-0:~# sudo apt install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-server : Depends: mysql-server-8.0 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel