Installing MSQL 8.0 Under WSL 2 and Ubuntu

Here's a PSA for those wanting to install MySQL Server 8.0 under the new Windows Subsystem for Linux 2 - WSL 2, with an Ubuntu distribution.

Systemd is not available as a default in WSL 2, and init.d scripts are not run at startup.

What's more, if you install MySQL 8 from the deb package here https://dev.mysql.com/downloads/repo/apt/ - the default mysql.server helper script that is used to start or stop MySQL won't be installed.

One solution is to download the mysql.server.sh script from here - https://github.com/mysql/mysql-server/tree/8.0/support-files - and then copy and rename the script to /etc/init.d/mysql (make sure that it's also executable - chmod +x mysql)

You'll then need to set the default values for basdir, datadir and pid file locations.

Here's an excerpt with the top portion of the file and the settings that worked for me...

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/usr
datadir=/var/lib/mysql

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

# The following variables are only set for letting mysql.server find things.

# Set some defaults
mysqld_pid_file_path=/var/run/mysqld/mysqld.pid
if test -z "$basedir"

After this you should be able to start and stop MySQL as follows:

sudo service mysql start
sudo service mysql stop

 

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.