58BITS
  • Home
  • Tech Stuff
  • Other Stuff
  • Photos
  • About
  • Contact
58BITS
  • Home
  • Tech Stuff
  • Installing MySQL 8.0 Under WSL 2 and Ubuntu

Installing MySQL 8.0 Under WSL 2 and Ubuntu

Submitted on May 02, 2020, 11:38 p.m.

Here's a PSA for those wanting to install MySQL Server 8.0 under the new Windows Subsystem for Linux - 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

Updated: In this post https://www.58bits.com/blog/2020/05/30/wsl-2-setup-development  I created a helper script that I use to start and stop the services I need under WSL 2...

#!/bin/bash
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo service mysql "$@"
sudo service php7.3-fpm "$@"
sudo service nginx "$@"
SOLR_ULIMIT_CHECKS=false /opt/solr/bin/solr "$@"

For whatever reason, I need to check that the /var/run/mysqld directory exists and permissions are set before starting MySQL.

I then alias the following commands in my .localrc or .local.fish files:

#wsl
alias wsl-up='~/Scripts/windows/wsl-exec-services.sh start'
alias wsl-down='~/Scripts/windows/wsl-exec-services.sh stop'

If I've rebooted, or I want to switch to another distribution running similar services, I run wsl-up, or wsl-down as needed.

 

Featured

ความเสี่ยงที่เกี่ยวข้องกับเทคโนโลยีหน้าจอสำหรับเด็ก (วัยก่อนรุ่นและวัยรุ่น)

ความเสี่ยงที่เกี่ยวข้องกับเทคโนโลยีหน้าจอสำหรับเด็ก (วัยก่อนรุ่นและวัยรุ่น)

Sep 15, 2024, 10:53 a.m.
An Executive Summary of the Current State of AI

An Executive Summary of the Current State of AI

Jul 20, 2024, 5:45 p.m.
Digital Media Preservation - Why Media Organizations Can’t Archive

Digital Media Preservation - Why Media Organizations Can’t Archive

Sep 17, 2012, 11:59 a.m.
The Long Road Home

The Long Road Home

Nov 09, 2011, 8:12 p.m.

Latest

อันตรายที่ซ่อนเร้นของน้ำตาล: ผลกระทบต่อสมองเด็กและสุขภาพผู้ใหญ่

Nov 27, 2024, 2:36 a.m.

General Purpose Encrypt and Decrypt Functions with Jose

Sep 16, 2024, 11:19 p.m.

ความเสี่ยงที่เกี่ยวข้องกับเทคโนโลยีหน้าจอสำหรับเด็ก (วัยก่อนรุ่นและวัยรุ่น)

Sep 15, 2024, 10:53 a.m.

Migrating a Google Workspace Account to a Personal Google Gmail Account

Aug 04, 2024, 9:30 p.m.
58bits

Tech, art, and life...

Copyright © 2026 Anthony Bouch. All rights reserved.

Made with ❤️ by Infonomic

Explore
  • Home
  • Tech Stuff
  • Other Stuff
  • Photos
Legal
  • Terms of Use
  • Privacy Policy
  • Cookies
Connect
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Copyright © 2026 Anthony Bouch. All rights reserved.

Made with ❤️ by Infonomic

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.