Install MySQL on WSL

visibility 2,610 comment 0 access_time 9m languageEnglish

Prerequisites

Before installing MySQL on WSL, please ensure you have WSL enabled on your Windows 10 system. 

Follow Install Windows Subsystem for Linux on a Non-System Drive to install WSL on a non-C drive. 

This tutorial provides steps to install MySQL on WSL Debian distro. You can follow similar steps to install it in other Linux distros. 

Step by step guide

  1. Open Debian distro through WSL command:
    wsl -d Debian
  2. Update Debian packages:
    sudo apt update

    You need to type user password.

  3. Install MySQL using the following command:
    sudo apt install mysql-server

    Type Y to continue when asked.

  4. Wait until the installation is completed. 
  5. Verify MySQL version:
    $ mysql --version
    mysql  Ver 15.1 Distrib 10.1.48-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Test MySQL

  1. Start MySQL service using the following commands:
    $ sudo service mysql start
    # Or
    sudo /etc/init.d/mysql start
  2. Check the status of the service:
    $ sudo service mysql status
    # Or
    sudo /etc/init.d/mysql status
    The output looks like the following:
    [info] /usr/bin/mysqladmin  Ver 9.1 Distrib 10.1.48-MariaDB, for debian-linux-gnu on x86_64
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Server version          10.1.48-MariaDB-0+deb9u1
    Protocol version        10
    Connection              Localhost via UNIX socket
    UNIX socket             /var/run/mysqld/mysqld.sock
    Uptime:                 1 min 33 sec
    
    Threads: 1  Questions: 63  Slow queries: 0  Opens: 32  Flush tables: 1  Open tables: 26  Queries per second avg: 0.677.
  3. Start security script prompts:
    sudo mysql_secure_installation
  4. Try MySQL prompt using the following command:
    sudo mysql
  5. Check databases:
    show databases;

    The output looks like the following screenshot:


  6. Type exit; to exit the CLI.
  7. Stop the service using the following command:
    $ sudo service mysql stop
    # Or
    sudo /etc/init.d/mysql stop
copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Tags
More from Kontext