WSL安装MySql

have to admit that WSL is not befect.

General tutorial always bring up ERROR:

1
2
$ service mysql start
mysql: unrecognized service

Luckily, I found an issue in WSL Github:(a bit modified)

1.Remove MySQL 8.x:

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

2.Change to MySQL 5.x candidate:

get download url from https://dev.mysql.com/downloads/file/?id=487007 or download the .deb directly

1
2
wget https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

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

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

4.Install MySQL 5.x

1
2
sudo apt-get -y install mysql-server
sudo service mysql start #(this should work without error)

5.Change to MySQL 8.x candidate

1
2
3
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb (select 8.x)
sudo apt policy mysql-server (it will show 8.x is the default candidate)
sudo apt-get update

however, I still find that the candidate is 5.x.

1
2
3
4
5
6
7
8
9
10
$ sudo apt policy mysql-server
mysql-server:
Installed: (none)
Candidate: 5.7.27-0ubuntu0.18.04.1
Version table:
5.7.27-0ubuntu0.18.04.1 500
500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 Packages
500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security/main amd64 Packages
5.7.21-1ubuntu1 500
500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic/main amd64 Packages

Continue the tutorial and I found out that it will download 8.x after all, so just go ahead!

6.Install MySQL 8.x

1
2
3
sudo apt-get -y install mysql-server
Modify a script as there is a bug
sudo vim /etc/init.d/mysql

search for a line “. /usr/share/mysql/mysql-helpers” and change it to
“. /usr/share/mysql-8.0/mysql-helpers”

7.Upgrade system tables to MySQL 8.x

1
2
sudo service mysql start #(this should start without error)
sudo mysql_upgrade -u root -p

then enjoy your MySQL.