Connecting MySQL in WSL/Ubuntu

PLEASE HELP!!! I have been hard stuck for over a week trying to get Ubuntu to connect to MySQL and I have had no joy AT ALL! I have tried everything I could find online, even did 2 fresh installs from step one. I am win10 machine, the error log tells me:

“”" Linux Native AIO interface is not supported on this platform. Please check your OS documentation and install appropriate binary of InnoDB."""

I have not found a solution. Please help.

Mosh…we REALLY need you to step up and help with this one.

There are a number of suggestions here (also you can see some of the ways that folks have checked error logs to get a better idea of what’s wrong). Hard to say which solution is best so read carefully and start with the ones that make most sense to you.
Linux Native AIO interface is not supported on this platform. · Issue #3631 · microsoft/WSL · GitHub

I personally still consider WSL an “experimental” technology in windows - its nice but it is not the real thing. Consider trying a virtual machine or dual-booting your pc so that it actually runs linux natively as other options. I personally run my database on an older pc I bought for $150 USD that runs a bare metal linux server to handle my databases for me - so there are always options. Since you have a windows pc you might be able to install MySql on the “windows” OS and still use it from WSL (I don’t really know for sure though).

Thank you. I had previously read those suggestions. At the time none of them resolved my challenge. What did resolve part of the challenge was to follow this suggestion:

https://forum.codewithmosh.com/t/pipenv-install-mysqlclient-error-solution/12582

That resolved the mysql start up and setup as I was able to at least get the database set up. Now I am running head first into a major buzzsaw trying to get Ubuntu/Linux to populate the database. It is refusing to connect to it because I get a an error telling me it does not recognize a socket:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

My current research is not yielding anything fruitful. I do not understand the error, and suggestions I have found for modifying it, do not share how to locate the var/run/… location. And even if I get it sorted out, I am not confident I will be able to complete the course as it appears that everything is geared toward Celery for production and I do not have the level of understanding of how to “go it alone” by using different approaches.

Thank you for your suggestions about potential solutions, but I am not versed enough in software or hardware to have any confidence that I could achieve what you suggest. As it is I have to Google particular terms and phrases to try and even understand what is going on in certain situations.

Which course (CodeWithMosh course) are you taking? Is it part of the course to run on WSL? Also for what its worth have you tried following the instructions from Microsoft (always a good place to start) for installing mySQL? Are you trying to run everything entirely in and completely in WSL? If there is any database that gives many little problems at installation it is MySQL so you have to be patient and keep trying … or move on to PostgreSQL if you have a choice :slight_smile:

Sockets are just the normal way Linux operating systems communicate between the operating system and the DB server but it’s a little unclear how WSL is supporting socket communication - there may be wrinkles in this case to iron out. For instance, one (simply possible) solution may be to communicate via http instead or who knows what else - MySQL does have a lot of configuration options that can be tweaked when things aren’t working.

I’m going through the Django course. I’m on sec. 3. Celery does not support windows, so I am following the pdf provided for windows users in the course and that is my pain point. I am at the last part of the install trying to populate the DB, I’ve been doing that via the WSL:Ubuntu terminal, and it will not connect. To be honest, the last part of the pdf is not clear if it is to be run in WSL or pipenv for the DB population, but it reads as if it iseant to be run WSL.

I will read MS MySQL docs and see what I can learn.

Thank you for the encouragement

I see. I am in the second Django course now. It looks like everything is done in the VSCode Terminal window once you have connected VSCode to your WSL environment - which in general behaves like any terminal. But you probably do need to be in the correct pipenv environment - otherwise I don’t think any manage.py stuff will work. Generally speaking, the MySQL server should be installed and running in WSL independently so you can and should be able to connect to it from any terminal and so on. But the specific migration tasks and seed_db tasks need to be handled by Django in the python environment where you are running your Django application (and this does mean that Django needs to be able to make a successful connection).

I can have a play with this in a week or two when I catch up to you, but I have been using Postgres all along (I don’t much like MySQL anymore to be honest - it seems like the worst of all worlds nowadays).

Well, I just opened everything up to try and see if I can make any progress, and nothing has changed.

#1: I have successfully configured MySQL in WSL and moved onto “Start the Project” in the pdf.

This is where it gets fuzzy, the way it reads makes me believe that installing the dependencies and populating the DB is to be done in WSL/Ubuntu:

Following the steps (dependencies installed):

pipenv install
Installing dependencies from Pipfile.lock (d4e163)…
:snake: ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 42/42 — 00:00:07
(storefront3-ed69_rKP)

This is the buzz saw I am dealing with and have not been able to get past, populating the DB. Every time I try I get this error:

MySQLdb._exceptions.OperationalError: (2002, “Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (13)”) (research has stated that the socket is not being created)

which leads to this error:

django.db.utils.OperationalError: (2002, “Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (13)”)

No amount of research has shown me how to fix this. I have removed and reinstalled MySQL several times following all kinds of suggestions (purge, clean, remove, chown/chmod (attempting to change where it looks) I’ve tried forcing it and nothing has worked.

I don’t know what to do or how to proceed. Today marks 10 days since I have run into this.

Hi,

I ran into the exact same issue. For me it was because of permissions. First check if your server is up and running by typing

sudo service mysql status

If it’s running then type following. This will give root user the necessary permissions to read and write.

sudo chmod -R 755 /var/run/mysqld

and finally restart the mySQL server

sudo service mysql restart

You can type all of the above commands in ubuntu. And then do python manage.py migrate in your vscode terminal, make sure you are in storefront3 virtual environment (pipenv shell) and settings file have correct username and password, if you were following the pdf, mosh asked to change the password.

2 Likes

Hi Quentin,

I ran into the same issue, and here’s what I did to solve it.
It’s actually a small fix.

Go to your settings.py, then change the DATABASE configurations of HOST to ‘127.0.0.1’ instead of ‘localhost’.

It should look like this:

image

Actually, that’s it!
Good luck!

3 Likes

Thank you. It’s always a small thing.

I took your suggestion about PostgreSQL, I have it running-ish, it refuses to populate the products tables. Still took me a ton of time to get it sorted out.

FWIW, I am using (attempting) Dramatiq for the task manager, I’m on a Windows machine. It’s a slog for me, but I’ll get it sorted out, eventually.

I will try your fix and let you know how it goes.

Thanks for your help.

Q

I ran into the same issue, all installations have been successful, the mysql service was up and running I could connect to mysql via console.
This little hint did the difference!
Thy a lot!

You are my HERO bro )) :ok_hand:

thx for your help, it worked