Score:1

Unable to run/uninstall/reinstall mysql on Ubuntu 20.04

cn flag

After a regular upgrade of Ubuntu 20.04, I was unable to run mysql again. I got this error.

xxx@xxx:/etc/mysql$ mysql  

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I tried various combinations for about 5 hours but none of them worked. I am happy to get rid of the current databases if at all they exist now.

Here is what I get when I try to uninstall the mysql server:

xxxx@xxx:/etc/mysql$ sudo apt remove mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-server' is not installed, so not removed
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up mysql-server-8.0 (8.0.25-0ubuntu0.20.04.1) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
mysqld will log errors to /var/log/mysql/error.log
2021-06-11T12:46:36.625455Z 0 [ERROR] [MY-010946] [Server] Failed to start mysqld daemon. Check mysqld error log.
Warning: Unable to start the server.
Failed to preset unit: File mysql.service: Link has been severed
/usr/bin/deb-systemd-helper: error: systemctl preset failed on mysql.service: No such file or directory
Failed to start mysql.service: Unit mysql.service not found.
invoke-rc.d: initscript mysql, action "start" failed.
Unit mysql.service could not be found.
dpkg: error processing package mysql-server-8.0 (--configure):
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

The output of the /var/log/mysql/error.log file which is shown in the above output is as follows:

2021-06-11T12:39:33.378397Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds inste>
2021-06-11T12:39:33.379542Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.25-0ubuntu0.20.04.1) starting as process 9109
2021-06-11T12:39:33.380367Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future>
2021-06-11T12:39:33.608401Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-11T12:39:33.629330Z 1 [ERROR] [MY-012263] [InnoDB] The Auto-extending innodb_system data file './ibdata1' is of a different size 768 pages (rounded down to MB) than specified in the>
2021-06-11T12:39:33.629486Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
2021-06-11T12:39:34.129573Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2021-06-11T12:39:34.129950Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2021-06-11T12:39:34.130270Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-06-11T12:39:34.131554Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.25-0ubuntu0.20.04.1)  (Ubuntu).

And output of the following command gives:

Your help in this regard is highly appreciated. I don't want to do a fresh installation of Ubuntu again.

Thank you.

Score:0
cn flag

Finally I managed to uninstall completely.

First, check if there is any active mysql related service by running:

ls /etc/systemd/system

I had mysqld.service and mysql.service active, I could remove both by running the following command

systemctl disable mysqld.service
systemctl daemon-reload
systemctl reset-failed

For the above commands, refer: https://superuser.com/questions/513159/how-to-remove-systemd-services

Then finally I ran for complete removal of mysql:

sudo apt --purge remove mysql-common

Note: In case you encounter the following error:

update-alternatives: error: alternative path  /etc/mysql/my.cnf.fallback doesn't exist

You may create symbolic links such as the one below:

 sudo ln -s /etc/mysql/my.cnf /etc/alternatives/my.cnf

now if you have already deleted the folder /etc/mysql, not a problem, create it again and create a dummy file by the name my.cnf using:

sudo touch /etc/mysql/my.cnf
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.