Install MariaDB Server on WSL

Kontext Kontext event 2022-06-06 visibility 11,345 comment 1
more_vert
Install MariaDB Server on WSL

MariaDB Server is one of the most popular open source relational databases and was created by the original developers of MySQL and guaranteed to stay open source. 

Prerequisites

Before installing MariaDB on WSL, please ensure you have WSL enabled on your Windows 10/11 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 MariaDB on WSL Ubuntu 20.04 distro. You can follow similar steps to install it in other Linux distros. 

warning If you have installed MySQL on the same WSL distro, the setup will overwrite the data directory.

Step by step guide

  1. Open Ubuntu distro through WSL command:
    wsl -d "Ubuntu-20.04"
    # Or the following name if the name has no version in it
    wsl -d "Ubuntu"

    *Remember to change the distro name accordingly.

  2. Update Ubuntu packages:
    sudo apt update

    You need to type user password.

  3. Install MariaDB server using the following command:
    sudo apt install mariadb-server

    Type Y to continue when asked.

  4. If you have installed MySQL before in the same WSL, the data will be overwritten:
    20220606114408-image.png
  5. Wait until the installation is completed. 
  6. Verify MariaDB version:
    $ mariadb --version
    mariadb  Ver 15.1 Distrib 10.3.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Test MariaDB

  1. Start MariaDB service using the following commands:
    $ sudo /etc/init.d/mysql start
     * Starting MariaDB database server mysqld                                                                       [ OK ]

  2. Check the status of the service:
    $ sudo /etc/init.d/mysql status
    The output looks like the following:
     * /usr/bin/mysqladmin  Ver 9.1 Distrib 10.3.34-MariaDB, for debian-linux-gnu on x86_64
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Server version          10.3.34-MariaDB-0ubuntu0.20.04.1
    Protocol version        10
    Connection              Localhost via UNIX socket
    UNIX socket             /var/run/mysqld/mysqld.sock
    Uptime:                 48 sec
    
    Threads: 6  Questions: 61  Slow queries: 0  Opens: 33  Flush tables: 1  Open tables: 26  Queries per second avg: 1.270
  3. Start security script prompts:
    sudo mysql_secure_installation

    The following are the output:

    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    
    Enter current password for root (enter for none):
    OK, successfully used password, moving on...
    
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.
    
    You already have a root password set, so you can safely answer 'n'.
    
    Change the root password? [Y/n] n
     ... skipping.
    
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n] n
     ... skipping.
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] Y
     ... Success!
    
    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] n
     ... skipping.
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] Y
     ... Success!
    
    Cleaning up...
    
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    
    Thanks for using MariaDB!
  4. Try MySQL prompt using the following command:
    sudo mariadb
    #or
    sudo mysql
  5. Check databases:
    show databases;

    The output looks like the following screenshot:

    20220613114828-image.png

  6. Type exit; to exit the CLI.
  7. Stop the service using the following command:
    $ sudo /etc/init.d/mysql stop
More from Kontext
comment Comments
M Markus Gallagher

Markus access_time 2 years ago link more_vert

In step 1. of chapter "Test MariaDB" you will want to start mariadb with the following command:

sudo /etc/init.d/mariadb start

In step 2. of chapter "Test MariaDB" you will want to check the mariadb status the following command:

sudo /etc/init.d/mariadb status

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts