Set up MySQL database on WSL

John Varghese
4 min readOct 4, 2021

Well I would like to show you here how to set up MySQL database on a Windows Subsystem for Linux (WSL) on your Windows Laptop or Desktop without a virtual machine or dual boot set up. You are like what, can we do that, yes I had similar thoughts ! But by the way what is a WSL ?

MySQL Database on WSL

What is a Windows Subsystem for Linux (WSL) ?

The Windows Subsystem for Linux lets you run a Linux environment directly on Windows without the overhead of a traditional virtual machine or dualboot setup.

Prerequisites: You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 for installing WSL.

How do you Install WSL on your Windows Laptop ?

  1. Click on Start
  2. Select Windows logo key + R, type “optionalfeatures.exe”, select OK.

3. Select “Windows Subsystem for Linux” and click Ok. Let the Install complete and Restart the machine.

4. You can choose your favorite GNU/Linux distributions from the Microsoft Store. As a part of our lab, we are going to choose “Ubuntu” and install the software. Restart your PC once again.

Microsoft Store for WSL
Click Get and Install the Ubuntu from Microsoft Store

The first time you launch a newly installed Linux distribution, a console window will open and you’ll be asked to wait for a minute or two for files to de-compress and be stored on your PC. All future launches should take less than a second.

You will then need to create a user account and password for your new Linux distribution.

What is MySQL ?

MySQL is an open-source SQL relational database, organizing data into one or more tables in which data types may be related to each other. It is vertically scalable, which means one ultimate machine will do the work for you. It is currently the most widely used of the four database systems.

How do you Install MySQL on WSL ?

  1. Open your WSL terminal (i.e.. Ubuntu).

2. Update your Ubuntu packages: sudo apt update

3. Once the packages have updated, install MySQL with: sudo apt install mysql-server

4. Confirm installation and get the version number: mysql --version

You may also want to run the included security script. This changes some of the less secure default options for things like remote root logins and sample users. To run the security script: Start a MySQL server: sudo /etc/init.d/mysql start and Start the security script prompts: sudo mysql_secure_installation

The first prompt will ask whether you’d like to set up the Validate Password Plugin, which can be used to test the strength of your MySQL password. You will then set a password for the MySQL root user, decide whether or not to remove anonymous users, decide whether to allow the root user to login both locally and remotely, decide whether to remove the test database, and, lastly, decide whether to reload the privilege tables immediately.

5. To open the MySQL prompt, enter: sudo mysql

To see what databases you have available, in the MySQL prompt, enter: SHOW DATABASES; To create a new database, enter: CREATE DATABASE database_name; To delete a database, enter: DROP DATABASE database_name;

Why our Customers may choose MySQL ?

Many of the world’s largest and fastest-growing organizations including Facebook, Twitter, Booking.com, and Verizon rely on MySQL to save time and money powering their high-volume Web sites, business-critical systems and packaged software.

Further Reading

MySQL :: Getting Started with MySQL

MySQL :: MySQL Books

MySQL :: Why MySQL?

MySQL :: Benchmarks

MySQL :: MySQL TCO Savings Calculator

Thank you taking the time to read MySQL install on WSL with me !

Follow me on Linkedin, if you have come this far !!

--

--

John Varghese

My Superpowers : Database Administrator, Badass Programmer, Miracle Worker for Customers, Can fly with Cloud, Can Balance on two foot, I can so you can too.