Just to be clear, is your python app running in WSL or Windows?
Also, did you add the line bind-address=0.0.0.0 in your /etc/mysql/my.cnf?
I don't know your connection config, but double-check you are using the same host. 127.0.0.1 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=0.0.0.0 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.
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:
[client-server]
# 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?
"I had a similar issue when setting up MariaDB on WSL2 – everything worked fine from the terminal, but SQLAlchemy and DataGrip couldn't connect.
What helped me:
1️⃣ Grant access to the user beyond localhost:
sql
Copy code
GRANT ALL PRIVILEGES ON . TO 'admin'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
2️⃣ Ensure MariaDB is listening on the correct port:
Check the port in use:
bash
Copy code
sudo netstat -tulnp | grep mysql
If MariaDB is running on a non-default port (e.g., 3307), try explicitly specifying it in DataGrip or SQLAlchemy:
bash
Copy code
sudo ufw allow 3307/tcp
sudo systemctl restart mariadb
4️⃣ Consider a containerized approach:
If the issue persists, deploying MariaDB in an isolated environment might help. I had success running a headless eCommerce system on Ubuntu 22.04 using this step-by-step deployment guide, and the database connection worked without any conflicts.
Try these steps—containerization might resolve compatibility issues. Hope this helps!"
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just to be clear, is your python app running in WSL or Windows?
Also, did you add the line
bind-address=0.0.0.0in your/etc/mysql/my.cnf?I don't know your connection config, but double-check you are using the same host.
127.0.0.1andlocalhostis 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=0.0.0.0in/etc/mysql/my.cnfis no longer necessary. I can connect to my MariaDB from both WSL and Windows app with sqlalchemy and pymysql.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
adminuser with root privilege.I'd love to provide you with more detail. Here is my
my.cnf:I tried both what you described in this blog post and not binding the address. Both not working.
Would you mind share your
my.cnfwith me?Here is my complete setup:
Clean uninstall:
Then
Start the service:
Config by following this
edit
/etc/mysql/my.cnf(optional)Then restart mariaDB:
sudo service mysql restart
"I had a similar issue when setting up MariaDB on WSL2 – everything worked fine from the terminal, but SQLAlchemy and DataGrip couldn't connect.
What helped me:
1️⃣ Grant access to the user beyond localhost:
sql
Copy code
GRANT ALL PRIVILEGES ON . TO 'admin'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
2️⃣ Ensure MariaDB is listening on the correct port:
Check the port in use:
bash
Copy code
sudo netstat -tulnp | grep mysql
If MariaDB is running on a non-default port (e.g., 3307), try explicitly specifying it in DataGrip or SQLAlchemy:
python
Copy code
engine = create_engine("mysql+pymysql://admin:password@127.0.0.1:3307/db_name")
3️⃣ Adjust WSL2 firewall settings:
bash
Copy code
sudo ufw allow 3307/tcp
sudo systemctl restart mariadb
4️⃣ Consider a containerized approach:
If the issue persists, deploying MariaDB in an isolated environment might help. I had success running a headless eCommerce system on Ubuntu 22.04 using this step-by-step deployment guide, and the database connection worked without any conflicts.
Try these steps—containerization might resolve compatibility issues. Hope this helps!"