8

I have purged and re-installed mysql-client and server a few times, I have rebooted my system and yet I cannot get mysql to work on my computer.

I ran these commands according to another askubuntu post:

sudo apt-get --purge remove mysql-server mysql-common mysql-client.

sudo apt update && sudo apt dist-upgrade && sudo apt autoremove.

sudo apt-get install -y mysql-server mysql-client

Then I rebooted and nothing happened.

Ouput of commands:

mysql -V

mysql  Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

sudo systemctl status mysql.service

Unit mysql.service could not be found.

sudo systemctl start mysql.service

Failed to start mysql.service: Unit mysql.service not found.

sudo systemctl start mysqld.service

Failed to start mysqld.service: Unit mysqld.service not found

I am not sure where to go from here as I have removed and purged and mysql seems to be installed just not working.

mysql -h localhost -P 3306 -u root -p or mysql -h 127.0.0.1 -P 3306 -u root -p

Same result:

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

cat mysql.cnf                                                           1 ↵
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

Any help is appreciated. Thank you.

<------UPDATE------> Just ran the commands recommended in comments and this is the output:

sudo apt-get install --reinstall mysql-server-8.0

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/1,228 kB of archives.
After this operation, 0 B of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 326219 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.20-0ubuntu0.20.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: warning: old mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: error processing archive /var/cache/apt/archives/mysql-server-8.0_8.0.20-0ubuntu0.20.04.1_amd64.deb (--unpack):
 new mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
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 while cleaning up:
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-8.0_8.0.20-0ubuntu0.20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

ls -laF /lib/systemd/system/mysql.service

-rw-r--r-- 1 root root 524 Nov  6 11:34 /lib/systemd/system/mysql.service

Got this error:: sudo apt-get install -f

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/1,228 kB of archives.
After this operation, 0 B of additional disk space will be used.
dpkg: error processing package mysql-server-8.0 (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Errors were encountered while processing:
 mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo dpkg --configure -a

dpkg: error processing package mysql-server-8.0 (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Errors were encountered while processing:
 mysql-server-8.0
1
14

Try

sudo apt-get install --reinstall mysql-server-8.0

and check if mysql.service exists

ls -laF /lib/systemd/system/mysql.service

To fix broken packages

sudo apt-get install -f
sudo dpkg --configure -a

Fix mysql.service that may have been left over from an old installation

sudo killall mysqld
sudo systemctl disable mysql.service
sudo rm -rf /lib/systemd/system/mysql.service
sudo rm -rf /usr/lib/systemd/system/mysql.service
sudo rm -rf /etc/systemd/system/multi-user.target.wants/mysql.service
sudo rm -rf /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/mysql.service
sudo rm -rf /var/cache/apt/archives/mysql-server-*.deb

sudo apt-get install -f
sudo dpkg --configure -a

sudo apt-get install --reinstall mysql-server-8.0

10
  • Hi @ExploitFate, just ran the commands you recommended and am still getting an error. Please see my updated post which shows the output. Thank you. – PA-GW May 5 '20 at 20:15
  • sudo apt-get install -f should fix it – ExploitFate May 5 '20 at 20:19
  • Got another error when running sudo apt-get install -f – PA-GW May 5 '20 at 20:21
  • Is dpkg --configure -a also exit with error? – ExploitFate May 5 '20 at 20:23
  • 1
    Thank you so much ExploitFate for your answer above (first answer). Spent about 8 hours using other posts to try and install mysql-server on ubuntu 20.04. I have an Ampps stack running which contains a mysql directory in a non standard location and was hoping not to have to unistall that, and in the end I did not have to, so thanks a million! – John Loughran May 6 at 12:39
5

Regarding this specific error:

Unit mysql.service could not be found.

[I'm running Ubuntu 20.04]

I spent a few hours on it before I discovered this: Months ago I played with MariaDB and had uninstalled it, but apparently it didn't get completely/cleanly uninstalled. It left two symlinks in

ls /etc/systemd/system
mysql.service -> /lib/systemd/system/mariadb.service
mysqld.service -> /lib/systemd/system/mariadb.service

The linked files had been removed by not the links themselves. I ran "unlink" on both the links, uninstalled all mysql packages with dpkg -P and reinstalled and it came up fine.

[I'm running Ubuntu 20.04] Good Luck.

0

I encountered the same issue and followed all the prior instructions blindly but to no avail. To fix the issue I did do the following.

  1. I renamed the /etc/mysql/FROZEN to _FROZEN

     stephen@stephen-ubuntu:~$ sudo mv /etc/mysql/FROZEN _FROZEN
    
  2. I ran the command:

     stephen@stephen-ubuntu:~$ sudo apt-get install --reinstall mysql-server-8.0
     Reading package lists... Done
     Building dependency tree       
     Reading state information... Done    
     0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 81 not upgraded.    
     Need to get 0 B/1,249 kB of archives.
     After this operation, 0 B of additional disk space will be used.    
     Preconfiguring packages ...    
     (Reading database ... 262947 files and directories currently installed.)    
     Preparing to unpack .../mysql-server-8.0_8.0.21-0ubuntu0.20.04.4_amd64.deb ...    
     Downgrade from (at least) 10.3 to 5.7 is not possible.    
     MySQL has been frozen to prevent damage to your system. Please see /etc/mysql/FROZEN for help.    
     Unpacking mysql-server-8.0 (8.0.21-0ubuntu0.20.04.4) over (8.0.21-0ubuntu0.20.04.4) ...    
     Setting up mysql-server-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     MySQL has been frozen to prevent damage to your system. Please see /etc/mysql/FROZEN for help.    
     Processing triggers for systemd (245.4-4ubuntu3.2) ...    
    
  3. Since one of the lines said to downgrade to 5.7 (including the new /etc/mysql/FROZEN file) and being desperate, I attempted to down grade MySQL.

     stephen@stephen-ubuntu:~$ sudo apt install mysql-server-5.7    
     Reading package lists... Done    
     Building dependency tree          
     Reading state information... Done    
     Package mysql-server-5.7 is not available, but is referred to by another package.    
     This may mean that the package is missing, has been obsoleted, or     
     is only available from another source    
     However the following packages replace it:    
       mariadb-server-10.3    
     E: Package 'mysql-server-5.7' has no installation candidate
    
  4. I noted that 'mysql-server-5.7' was replaced by 'mariadb-server-10.3' so I gave it a go!

     stephen@stephen-ubuntu:~$ sudo apt install mariadb-server-10.3    
     Reading package lists... Done    
     Building dependency tree           
     Reading state information... Done    
     The following additional packages will be installed:    
       galera-3 libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libreadline5 libterm-readkey-perl mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common      
       mariadb-server-core-10.3 socat      
     Suggested packages:    
       libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl mailx mariadb-test tinyca      
     The following packages will be REMOVED:    
       mysql-client-8.0 mysql-client-core-8.0 mysql-server-8.0 mysql-server-core-8.0      
     The following NEW packages will be installed:    
       galera-3 libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libreadline5 libterm-readkey-perl mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common      
       mariadb-server-10.3 mariadb-server-core-10.3 socat      
     0 upgraded, 12 newly installed, 4 to remove and 81 not upgraded.    
     Need to get 19.3 MB of archives.    
     After this operation, 25.1 MB disk space will be freed.    
     Do you want to continue? [Y/n]     
     Get:1 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-common all 1:10.3.22-1ubuntu1 [15.6 kB]    
     Get:2 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 galera-3 amd64 25.3.29-1 [898 kB]    
     Get:3 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 libdbi-perl amd64 1.643-1 [730 kB]    
     Get:4 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 libconfig-inifiles-perl all 3.000002-1 [40.6 kB]    
     Get:5 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 libreadline5 amd64 5.2+dfsg-3build3 [100 kB]    
     Get:6 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-client-core-10.3 amd64 1:10.3.22-1ubuntu1 [5,805 kB]    
     Get:7 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-client-10.3 amd64 1:10.3.22-1ubuntu1 [1,125 kB]    
     Get:8 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-server-core-10.3 amd64 1:10.3.22-1ubuntu1 [6,011 kB]    
     Get:9 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 socat amd64 1.7.3.3-2 [323 kB]    
     Get:10 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-server-10.3 amd64 1:10.3.22-1ubuntu1 [4,188 kB]    
     Get:11 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 libdbd-mysql-perl amd64 4.050-3 [82.8 kB]    
     Get:12 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 libterm-readkey-perl amd64 2.38-1build1 [24.6 kB]    
     Fetched 19.3 MB in 1s (20.0 MB/s)                   
     Preconfiguring packages ...    
     (Reading database ... 262947 files and directories currently installed.)    
     Removing mysql-server-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     Removing mysql-client-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     Removing mysql-client-core-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     Removing mysql-server-core-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     Selecting previously unselected package mariadb-common.    
     (Reading database ... 262740 files and directories currently installed.)    
     Preparing to unpack .../0-mariadb-common_1%3a10.3.22-1ubuntu1_all.deb ...    
     Unpacking mariadb-common (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package galera-3.    
     Preparing to unpack .../1-galera-3_25.3.29-1_amd64.deb ...    
     Unpacking galera-3 (25.3.29-1) ...    
     Selecting previously unselected package libdbi-perl:amd64.    
     Preparing to unpack .../2-libdbi-perl_1.643-1_amd64.deb ...    
     Unpacking libdbi-perl:amd64 (1.643-1) ...    
     Selecting previously unselected package libconfig-inifiles-perl.    
     Preparing to unpack .../3-libconfig-inifiles-perl_3.000002-1_all.deb ...    
     Unpacking libconfig-inifiles-perl (3.000002-1) ...    
     Selecting previously unselected package libreadline5:amd64.    
     Preparing to unpack .../4-libreadline5_5.2+dfsg-3build3_amd64.deb ...    
     Unpacking libreadline5:amd64 (5.2+dfsg-3build3) ...    
     Selecting previously unselected package mariadb-client-core-10.3.    
     Preparing to unpack .../5-mariadb-client-core-10.3_1%3a10.3.22-1ubuntu1_amd64.deb ...    
     Unpacking mariadb-client-core-10.3 (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package mariadb-client-10.3.    
     Preparing to unpack .../6-mariadb-client-10.3_1%3a10.3.22-1ubuntu1_amd64.deb ...    
     Unpacking mariadb-client-10.3 (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package mariadb-server-core-10.3.    
     Preparing to unpack .../7-mariadb-server-core-10.3_1%3a10.3.22-1ubuntu1_amd64.deb ...    
     Unpacking mariadb-server-core-10.3 (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package socat.    
     Preparing to unpack .../8-socat_1.7.3.3-2_amd64.deb ...
     Unpacking socat (1.7.3.3-2) ...    
     Setting up mariadb-common (1:10.3.22-1ubuntu1) ...    
     update-alternatives: using /etc/mysql/mariadb.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode    
     Selecting previously unselected package mariadb-server-10.3.    
     (Reading database ... 263114 files and directories currently installed.)    
     Preparing to unpack .../mariadb-server-10.3_1%3a10.3.22-1ubuntu1_amd64.deb ...    
     /var/lib/mysql: found previous version 10.3    
     Unpacking mariadb-server-10.3 (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package libdbd-mysql-perl:amd64.    
     Preparing to unpack .../libdbd-mysql-perl_4.050-3_amd64.deb ...    
     Unpacking libdbd-mysql-perl:amd64 (4.050-3) ...    
     Selecting previously unselected package libterm-readkey-perl.    
     Preparing to unpack .../libterm-readkey-perl_2.38-1build1_amd64.deb ...    
     Unpacking libterm-readkey-perl (2.38-1build1) ... 
     Setting up libconfig-inifiles-perl (3.000002-1) ...    
     Setting up libreadline5:amd64 (5.2+dfsg-3build3) ...    
     Setting up socat (1.7.3.3-2) ...    
     Setting up mariadb-server-core-10.3 (1:10.3.22-1ubuntu1) ...    
     Setting up galera-3 (25.3.29-1) ...    
     Setting up mariadb-client-core-10.3 (1:10.3.22-1ubuntu1) ...    
     Setting up libterm-readkey-perl (2.38-1build1) ...    
     Setting up libdbi-perl:amd64 (1.643-1) ...    
     Setting up mariadb-client-10.3 (1:10.3.22-1ubuntu1) ...    
     Setting up libdbd-mysql-perl:amd64 (4.050-3) ...    
     Setting up mariadb-server-10.3 (1:10.3.22-1ubuntu1) ...    
     Installing new version of config file /etc/apparmor.d/usr.sbin.mysqld ...    
     Installing new version of config file /etc/init.d/mysql ...    
     Installing new version of config file /etc/logrotate.d/mysql-server ...    
     Installing new version of config file /etc/mysql/debian-start ...    
     mariadb.service is a disabled or a static unit, not starting it.    
     Processing triggers for libc-bin (2.31-0ubuntu9) ...    
     Processing triggers for systemd (245.4-4ubuntu3.2) ...    
     Processing triggers for man-db (2.9.1-1) ...
     Processing triggers for menu (2.1.47ubuntu4) ...
    

Subsequently I went to Synaptic to check for broken packages and 'mysql-server-8.0' was no longer there nor installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.