11

I am running Ubuntu 18.04 on WSL and I am trying to install MySQL-server

I keep get the error as displayed on the screenshot attached..I have tried several times to

  • apt remove --purge MySQL*
  • apt-get autoremove
  • apt-get autoclean

  • sudo dpkg --configure -a

  • sudo apt-get install -f

  • sudo apt-get dist-upgrade

Any ideas? I keep coming up with the same error.

error output

ellen
  • 119
  • 4
  • Please add all errors to the question in readable form. That console output is pure text, so there is no need to add an image – Nico Haase Jan 22 '20 at 15:45
  • Additionally, have you tried running the hints from https://stackoverflow.com/questions/54835516/windows-subsystem-install-mysql-server? – Nico Haase Jan 22 '20 at 15:48
  • Does this answer your question? [windows subsystem install mysql server](https://stackoverflow.com/questions/54835516/windows-subsystem-install-mysql-server) – Flimm Aug 15 '20 at 09:11

2 Answers2

2

As per your output, Its looks like package mysql-server depends on mysql-server-5.7 but mysql-server-5.7 was not configured properly in previous installation.So you can remove mysql-server-5.7 and its packages and install again.

Removing 'mysql-server-5.7` and its dependencies

sudo dpkg -r mysql-client-5.7
sudo dpkg -r mysql-server-5.7
sudo dpkg -r libmysqlclient20:i386
sudo dpkg -r libmysqlclient20:amd64
sudo dpkg -r libmysqlclient18:amd64
sudo dpkg -r mysql-common

Re-installing mysql-server

sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation
1

I had the exact same problem and I took these steps to fix it. If you want the quick TL;DR, just jump to either the step 2 (for MySQL 5.x) or the step 4 (for MySQL 8.x). I just include the other two steps as well to say more about what didn't work for me(but might be still helpful to someone else):

STEP1:

Some people get errors about sockets(just like pipes, sockets are things that make the communication between mysql server and its clients possible) and thus suggest using command line option --protocl=TCP or adding --protocol:tcp to the mysqld.conf to make it use TCP instead of these sockets(which are better for faster local connection). But there's the error Error writing /etc/mysql/mysqld.conf.d/mysqld.conf: No such file or directory" when I try to save that configuration file (initiated with "sudo nano"). I even cleaned up everything and installed mysql once again from scratch:

sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get remove --purge *mariadb*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt update
sudo apt upgrade
sudo apt-get install mysql-server

But still even that configuration file doesn't exist for me.

STEP2:

I see that running mysql says mysql.exe: command not found, so I think the main problem is with finding the executable from PATH. But the /etc/bin/mysql exists and also the /etc/bin is in the PATH, so I don't know why I get the command-not-found error when I run the mysql. Anyway, I run the /etc/bin/mysql and it gives yet another error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Accidentally, I try sudo mysql and all of a sudden it successfully connects to the mysql server and shows the version 5.7. i.e., only adding the sudo made it work! I am not a Linux guru but I [used to] think that when sudo is needed, I should get a permission error and not a mysql.exe: command not found.

STEP3:

I'm following a tutorial which is based on MySQL 8. So I think probably upgrading to MySQL version 8 might fix both of my issues(it turns out that the necessity of sudo is not an issue at all, it has to be there normally, if not configured otherwise). So I follow the instructions in here. I add the MySQL APT repositories to my repository list, and then apt update & re-install the mysql-server. This time, I get a window which asks about the version and I choose version 8. Installation finishes and sudo mysql --version gives mysql Ver 8.0.20 for Linux on x86_64 (MySQL Community Server - GPL), HOWEVER, this time even sudo mysql gives the error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2). Now even sudo is not helping!

STEP4:

I check the error log in /var/log/mysql/error.log and realize there's a problem with this description: Linux Native AIO interface is not supported on this platform. so I Google it and finally fix my issue with MySQL version 8 installation on WSL using this very helpful comment from @jw-redpanda:

Direct installation of MySQL 8.x will not work on WSL 1(that's probably the reason why we failed at step 3). It has problem starting the server. Steps below should work:

1. Remove MySQL 8.x:

sudo apt-get purge mysql-server mysql-client
sudo apt-get -y autoremove

2. Change to MySQL 5.x candidate:

sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb (if you don't have it, get it from here: https://dev.mysql.com/downloads/repo/apt/)

3. Double check current apt policy of MySQL is 5.x:

sudo apt-get update

4. Install MySQL 5.x

sudo service mysql start (this should work without error)

5. Change to MySQL 8.x candidate

sudo apt-get update
sudo apt policy mysql-server (it will show 8.x is the default candidate)

6. Install MySQL 8.x

sudo apt-get -y install mysql-server

7. Modify a script as there is a bug

sudo nano /etc/init.d/mysql
(search for a line ". /usr/share/mysql/mysql-helpers" and change it to
". /usr/share/mysql-8.0/mysql-helpers")

8. Upgrade system tables to MySQL 8.x

sudo service mysql start (this should start without error)
sudo mysql -u root -p

Hope this also works for you!

aderchox
  • 710
  • 1
  • 8
  • 16