2

I made a little pythonfile to test the connection to my database:

# Module Imports
import sys
import mariadb


# Connect to MariaDB Platform
try:
    conn = mariadb.connect(
        host = "127.0.0.1",
        port = 3306,
        database = "xxx",
        user = "xxx_admin",
        password = "xxx_admin"
    )
except mariadb.Error as e:
    print(f"Error connecting to MariaDB Platform: {e}")
    sys.exit(1)

# Get Cursor
cur = conn.cursor()

And what I get back is:

C:\Users\User\Desktop\xxx_test>python mariadb_test.py
19:53:29
Traceback (most recent call last):
  File "mariadb_test.py", line 5, in <module>
    import mariadb
  File "C:\Python37\lib\site-packages\mariadb\__init__.py", line 10, in <module>
    from ._mariadb import (
ImportError: Mariadb module initialization failed

Why do I get the time and failed the initialization of Mariadb?

DaBom
  • 73
  • 8
Jan
  • 21
  • 1
  • MariaDB Connector/C Python packages from pypi.org are statically linked against MariaDB Connector/C. So it looks like connector/c could not be initialized. Which Windows version do you use? – Georg Richter Nov 26 '20 at 13:02
  • I'm using Windows 10 and try to connect to the database in Xampp. It worked well till I used import datetime in my script. – Jan Nov 26 '20 at 13:25
  • 1
    But the script above doesn't import datetime module ?! – Georg Richter Nov 26 '20 at 13:39
  • I had it in my script but after it went wrong I removed it. Instead of MariaDB I tried mySQLdb and it gave the same error. – Jan Nov 26 '20 at 20:29
  • 1
    same error on popos(ubuntu) 22.04, py3.10, mariadb 1.1.5, any solutions? – OskarZyg Nov 24 '22 at 23:37
  • Please post the exact code that led to the exception, as well as the exact exception. Right now the exception says line 5 caused the error but that’s not lining up with your code. – jkr Dec 16 '22 at 13:21
  • Take a look at https://jira.mariadb.org/projects/CONPY/issues/CONPY-239 , check to see if renaming/moving files out of you running directory helps. Try upgrading to 1.1.6, the error message might be more informative using that version. – micromoses Dec 16 '22 at 14:23

1 Answers1

0

I tried in Ubuntu 22.04.1 LTS, which is running in Windows 11 WSL, with python 3.10.6 and mariadb 1.1.5.post3

It seems, you are getting while importing mariadb. I installed connector and mariadb package, and with this I am able to perform import mariadb

In Ubuntu, you can execute below to install mariadb connector:

sudo apt-get update -y
sudo apt-get install -y libmariadb-dev
pip install mariadb

Current version for libmariadb-dev is 1:10.6.11 (https://packages.debian.org/sid/libmariadb-dev)

After this, open python shell and

import mariadb

You can look this post as well, for more help: Problem with pip install mariadb - mariadb_config not found