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?

7
  • 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? Nov 26, 2020 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, 2020 at 13:25
  • 1
    But the script above doesn't import datetime module ?! Nov 26, 2020 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, 2020 at 20:29
  • 1
    same error on popos(ubuntu) 22.04, py3.10, mariadb 1.1.5, any solutions?
    – OskarZyg
    Nov 24, 2022 at 23:37

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.