Home > OS >  Python mariadb module does not connect to database on network
Python mariadb module does not connect to database on network

Time:12-01

I am trying to connect to a mariadb-database on my local network. using Python.

import mariadb

cursor = mariadb.connect(host='192.168.178.77', user='someuser', password='somepass', db='temps')

Output is:

Traceback (most recent call last):
  File "/Users/localuser/PycharmProjects/SQL/main.py", line 20, in <module>
    cursor = mariadb.connect(host='192.168.178.77', user='someuser', password='somepass', db='temps')
  File "/Users/user/.conda/envs/SQL/lib/python3.10/site-packages/mariadb/__init__.py", line 142, in connect
    connection = connectionclass(*args, **kwargs)
  File "/Users/localuser/.conda/envs/SQL/lib/python3.10/site-packages/mariadb/connections.py", line 86, in __init__
    super().__init__(*args, **kwargs)
mariadb.OperationalError: Can't connect to server on '192.168.178.77' (60)

I can connect via Pycharms Database functionality and send SQL Statements. I also can use DB management tools from that very host and use data without any issue. It even works from my phone.

This code is the only place where I get an error.

OS is MacOS13.0.1

Thank You!

CodePudding user response:

This happens due to a bug in MariaDB Connector/C. (Issue CONC-612).

The issue was fixed in C/C Version 3.3.3 - which is available via brew:

After

brew update
brew upgrade mariadb-connector-c

connection should work as expected.

CodePudding user response:

I've got the same problem recently. Add port variable and check other. If doesn't help, try mysql-connector-python it works similar. Or install mariadb connector manually

  • Related