have to admit that WSL is not befect.
General tutorial always bring up ERROR:
1 | service mysql start |
2 | mysql: unrecognized service |
Luckily, I found an issue in WSL Github:(a bit modified)
1.Remove MySQL 8.x:
1 | sudo apt-get purge mysql-server mysql-client |
2 | 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 | wget https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb |
2 | sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb |
3.Double check current apt policy of MySQL is 5.x:
1 | sudo apt policy mysql-server (it will show 5.x is the default candidate) |
2 | sudo apt-get update |
4.Install MySQL 5.x
1 | sudo apt-get -y install mysql-server |
2 | sudo service mysql start #(this should work without error) |
5.Change to MySQL 8.x candidate
1 | sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb (select 8.x) |
2 | sudo apt policy mysql-server (it will show 8.x is the default candidate) |
3 | sudo apt-get update |
however, I still find that the candidate is 5.x.
1 | sudo apt policy mysql-server |
2 | mysql-server: |
3 | Installed: (none) |
4 | Candidate: 5.7.27-0ubuntu0.18.04.1 |
5 | Version table: |
6 | 5.7.27-0ubuntu0.18.04.1 500 |
7 | 500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 Packages |
8 | 500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security/main amd64 Packages |
9 | 5.7.21-1ubuntu1 500 |
10 | 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 | sudo apt-get -y install mysql-server |
2 | Modify a script as there is a bug |
3 | 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 | sudo service mysql start #(this should start without error) |
2 | sudo mysql_upgrade -u root -p |
then enjoy your MySQL.