Error connecing with Database under WSL 2

Abhi D 1 Reputation point
2022-01-07T17:45:16.173+00:00

I am using latest Windows 11 build and installed WSL 2 (Debian) for development purpose. To try out a project, I need to install and configure MariaDB under my WSL Debian system. I have installed MariaDB 10.6.5 fine with no errors, but during initial setup process, I am having issues with connecting to MySQL. When I give following command:

sudo mysql_secure_installation

it's showing me error that
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)

I also tried following command:

sudo mysql_secure_installation --protocol=tcp

But it's showing error again
ERROR 2002 (HY000): Can't connect to server on 'localhost' (115)

What's the issue here? How to connect with MySQL under WSL 2?

Note: I don't have any MySQL client or anything related installed under Windows host, only WSL (Debian) has MariaDB installed.

Azure Database for MariaDB
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Saurabh Sharma 23,766 Reputation points Microsoft Employee
    2022-01-14T16:24:33.547+00:00

    Hi @Abhi D ,

    I am to repro your issue and it looks like you need to start the "mariadb" service using sudo service mariadb start before running the above command in debian 11. (see screenshot below)

    165195-image.png

    Please let me know this works for you.

    Thanks
    Saurabh

    1 person found this answer helpful.

  2. Saurabh Sharma 23,766 Reputation points Microsoft Employee
    2022-01-08T00:12:41.107+00:00

    Hi @Abhi D ,

    Thanks for using Microsoft Q&A !!

    You are getting this error as you have not started your mysql instance and you need to first execute the below command to start your mysql instance before try to restrict access the server using the command you are trying to run

    sudo service mysql start

    I am able to reproduce your issue and able to run your command sudo mysql_secure_installation after the start. Please check below -
    Error(Before staring mysql)
    163306-image.png

    After starting mysql
    163341-image.png

    Please let me know if you have any other questions.

    Thanks
    Saurabh

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.