DEV Community

Discussion on: Setting up WSL 2 for Web Development

hymanzhan profile image
Xucong ZHAN Author • Edited on

Just to be clear, is your python app running in WSL or Windows?
Also, did you add the line bind-address= in your /etc/mysql/my.cnf?
I don't know your connection config, but double-check you are using the same host. and localhost is not the same nor always interchangeable.

It's hard to tell what the problem is based on what you described, but I can try and replicate if that's also the case on my machine.

Update: OK I just tried, and it seems that with the latest WSL2 and MariaDB the bind-address= in /etc/mysql/my.cnf is no longer necessary. I can connect to my MariaDB from both WSL and Windows app with sqlalchemy and pymysql.

sqlalchemy to wsl mariadb

Thread Thread
quillen profile image
Quillen • Edited on

OK. I think not being able to connect from datagrip and sqlalchemy is related.
MariaDB is running on WSL2 and I am able to connect to it from the terminal. I created admin user with root privilege.

MariaDB [(none)]> select user, host from information_schema.processlist;
| user  | host      |
| admin | localhost |
1 row in set (0.000 sec)

I'd love to provide you with more detail. Here is my my.cnf:

# Port or socket location where to connect
# port = 3307
socket = /run/mysqld/mysqld.sock

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

I tried both what you described in this blog post and not binding the address. Both not working.
Would you mind share your my.cnf with me?

Here is my complete setup:

Clean uninstall:

sudo dpkg -l | grep mariadb 
 sudo apt-get purge mariadb*


sudo apt update
sudo apt install mariadb-server

Start the service:

sudo service mysql start

Config by following this

sudo mysql_secure_installation

edit /etc/mysql/my.cnf (optional)

port=3307 # or any port you like

Then restart mariaDB:
sudo service mysql restart