question

AbhiD-1179 avatar image
0 Votes"
AbhiD-1179 asked SaurabhSharma-msft commented

Error connecing with Database under WSL 2

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-mariadb
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SaurabhSharma-msft avatar image
0 Votes"
SaurabhSharma-msft answered SaurabhSharma-msft converted comment to answer

Hi @abhid-1179,

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.


image.png (10.3 KiB)
image.png (28.4 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

I have tried to start mysql, but it gave me an error:
mysql: unrecognized service

Also I tried with mysqld, but same error:
mysqld: unrecognized service

What's your operating system in WSL? I am running Debian 11 (Bullseye). I followed this tutorial to install mariaDB - https://computingforgeeks.com/how-to-install-mariadb-on-debian-linux/

0 Votes 0 ·

Hi @abhid-1179,

I have used Debian 9(Stretch). I will try checking with Debian 11 and get back to you.

Thanks
Saurabh

0 Votes 0 ·
SaurabhSharma-msft avatar image
1 Vote"
SaurabhSharma-msft answered SaurabhSharma-msft commented

Hi @abhid-1179,

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


image.png (48.7 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It solves my issue, Thank you.

0 Votes 0 ·

Hi @abhid-1179,

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

Thanks
Saurabh

0 Votes 0 ·

Hi @abhid-1179,

Please let me know if you find above reply useful. If yes, please 'Accept the answer' for the above reply. This will help other community members facing similar query to refer to this solution. Thanks.

Thanks
Saurabh

0 Votes 0 ·