7

I just installed WSL Ubuntu 20.04 and the first thing I've done is

 sudo apt-get update
 sudo apt-get upgrade
 sudo apt-get install mysql-server

and here what it gave me

Setting up mysql-server-8.0 (8.0.20-0ubuntu0.20.04.1) ...
invoke-rc.d: could not determine current runlevel
 * Stopping MySQL database server mysqld                                                                                                                         [ OK ]
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Cannot open /proc/net/unix: No such file or directory
Cannot stat file /proc/1/fd/5: Operation not permitted
Cannot stat file /proc/1/fd/10: Operation not permitted
Cannot stat file /proc/1/fd/6: Operation not permitted
Cannot stat file /proc/42/fd/7: Operation not permitted
Cannot stat file /proc/42/fd/10: Operation not permitted
Cannot stat file /proc/42/fd/5: Operation not permitted
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 3726
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package mysql-server-8.0 (--configure):
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1

and

dpkg: dependency problems prevent configuration of mysql-server:

 mysql-server depends on mysql-server-8.0; however:
  Package mysql-server-8.0 is not configured yet.

    dpkg: error processing package mysql-server (--configure):
     dependency problems - leaving unconfigured
    Setting up libcgi-pm-perl (4.46-1) ...
    No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                              Setting up libhtml-template-perl (2.97-1) ...
    Setting up libcgi-fast-perl (1:2.15-1) ...
    Processing triggers for systemd (245.4-4ubuntu3.1) ...
    Processing triggers for man-db (2.9.1-1) ...
    Processing triggers for libc-bin (2.31-0ubuntu9) ...
    Errors were encountered while processing:
     mysql-server-8.0
     mysql-server
    E: Sub-process /usr/bin/dpkg returned an error code (1)

then I tried sudo mysql_secure_installation

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

And this is not only on WSL.

mybrave
  • 1,662
  • 3
  • 20
  • 37
Dmitry Dmitriy
  • 71
  • 1
  • 1
  • 2

4 Answers4

5

I had the same problem as you; I did the following using Ubuntu 20.04 WSL version in Windows 10 and it helped me. First, because of the dependency problems - leaving unconfigured error, I followed this answer here to purge MySQL and attempt a reinstall:

sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get dist-upgrade

sudo apt-get install mysql-server

Having done that the problem remained (but certainly this was helpful anyway).

The next clue was the Can't connect to local MySQL server through socket error... The MySQL command is asking a password and providing the wrong one results in this error. The password hasn't been set yet, right? Wrong! Reading the MySQL 8.0 Reference Manual - Default Privileges the installation sets a random password initially. So the root password has to be changed first.

To do so I followed this answer. I copy that answer here for convenience:

On ubuntu I did the following:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking

Then run mysql in a new terminal:

mysql -u root

And run the following queries to change the password:

UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;

In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is 'authentication_string'.

Having quoted the answer, please note the PASSWORD() function has been deprecated as shared in this answer over here. As stated there, just replace it using any of the MySQL encryption functions I used MD5().

Finally:

sudo service mysql start
* Starting MySQL database server mysqld                     [ OK ]
halfer
  • 19,824
  • 17
  • 99
  • 186
Metafaniel
  • 29,318
  • 8
  • 40
  • 67
4

As the first step try these steps

sudo apt-get remove --purge mysql*

sudo apt-get purge mysql*

sudo apt-get autoremove

sudo apt-get autoclean

sudo apt-get remove dbconfig-mysql

sudo apt-get dist-upgrade

If you get the same error try to remove MySQL dpkgs. To do so try these steps

dpkg -l | grep mysql

Then you will see the mysql packages and remove them one by one

sudo apt purge [package_name]

or

sudo dpkg purge [package_name]

Although some pkgs won't be removed.Keep them as it is and try to install mysql server again.

sudo apt update

sudo apt install mysql-server

sudo mysql_secure_installation

Hope you got the answer. Thank you.

1

I encountered this issue on a fresh VPS. I resolved it by adding some swap space

# Add swap space on Ubuntu 20 (1000MB)
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10

then running

sudo apt-get install -y mysql-server

This workaround could work for WSL, too.

LuminiCode
  • 503
  • 1
  • 4
  • 10
0

when installation freezes

> sudo killall mysqld

and continue install

Amal K
  • 4,359
  • 2
  • 22
  • 44
Seyacat
  • 21
  • 2