Connect Python to MariaDB

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
SteveR
Level 3
Level 3
Posts: 167
Joined: Fri May 24, 2019 12:02 pm
Location: Morehead City, NC
Contact:

Connect Python to MariaDB

Post by SteveR »

Turned out that installing a Python to MariaDB connection on Linux Mint was not as simple as one would believe. The MariaDB website has a webpage devoted to installing a Python to MariaDB connector, so it appeared to be simple. A problem developed as the command "pip3 install mariadb" failed to work out-of-the-box. This command will eventually work after some installation gymnastics discussed below. Also note that other tutorials that I ran across when doing an internet search were outdated. This tutorial is based on using Mint 20.1. Eventually this tutorial will join the ranks of "outdated". Both MySQL and MariaDB have a lot of outdated tutorials. An unfortunate after effect resulting from new versions being developed.
  • If Python3-pip is not installed on your computer, it is available on the Mint repository under "software manager".
  • After downloading go to this webpage: MariaDB Connector/C. Go to the heading "Install via APT (Debian/Ubuntu)". Issue the command: "sudo apt install libmariadb3 libmariadb-dev". This is where the connector is loaded onto your computer for installation in the following steps.
  • In "/etc/mysql", create a directory: "mariadb-connector-python". Place the tarball: "connector-c-3.1.13/mariadb-connector-c-3.1.13-ubuntu-focal-amd64.tar.gz" in that directory. CD to that directory and unpack the tarball. Important: also see MariaDB Connector/Python. Read the tab: "Installing from Source" items 1-4. The list of items is helpful, but they had to be tweaked to work.
  • After unpacking, you can issue the command "pip3 install mariadb" to complete installation of the Python to MariaDB connector.
Good Luck!
rude
Level 1
Level 1
Posts: 6
Joined: Sun Mar 15, 2015 2:00 pm

Re: Connect Python to MariaDB

Post by rude »

Hi, I'm on 20.3.
Just installed MariaDB and DBeaver, and they connect perfectly.

Python 3.8.3 (in venv) cannot connect. Installed mariadb.connector following these instructions (cannot install libmariadb-dev) with no result.
The same with pymysql connector (no connection).

Anything else before going back to postgresql and psycopg?

Thanks & Byez
SteveR
Level 3
Level 3
Posts: 167
Joined: Fri May 24, 2019 12:02 pm
Location: Morehead City, NC
Contact:

Re: Connect Python to MariaDB

Post by SteveR »

Sorry, have no insight to offer you. Following its success, I put that project behind me,
Amazingly, I located the Python script, it still ran successfully. Since connecting to MariaDB with Python still works, I'm not really not in a position to go through all the tribulations of re-reviewing how to get Python to interact with MariaDB. My original post was back in March 2021. I don't know if anything has since become outdated. I suspect that since it is less than a year, I would not anticipate anything be outdated yet.
Post Reply

Return to “Tutorials”