Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't install mysql on pure ubuntu 20.04

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.

like image 353
Dmitry Dmitriy Avatar asked Jun 01 '20 08:06

Dmitry Dmitriy


People also ask

Why is MySQL not installing?

Re-run Installer From Start Menu Once the installer has completed, if the original attempt to install MySQL has failed, go to your Start Menu and look for an application called "MySQL installer". When you run the Application, you may be able to choose your configuration.


1 Answers

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 ]
like image 128
Metafaniel Avatar answered Sep 30 '22 05:09

Metafaniel