MariaDB Python Connector

Install the Python Connector on Rocky Linux 9.

If you are new to Python or struggling with the installation of MariaDB Python Connector on Linux, the following guide will take you from start to finish.


Requirements

To complete this blog, you will need a server with network connectivity and external internet access. Make sure to open the relevant firewalls. For testing purposes, high-specification servers are not required. You can use local virtual machines instead. In this guide, we will be using Digital Ocean Droplets with 2 vCPUs and 4GB RAM. All commands will be executed as the root user on the servers, using a RockyLinux 9 operating system. However, you can also use other flavours of Linux, such as CentOS.


Ensure the server you are using is up to date and install the Linux wget package:

Bash
yum update -y
yum install -y wget

I like to ensure my server has a hostname so that when I have multiple windows open, I know exactly where I am:

Bash
hostnamectl set-hostname application

Once you have set the hostname, log out and log back in again, and the hostname will be displayed.


I will set an environment variable to be my customer download token. As an enterprise customer, this is available to you from your customer service portal:

Bash
CUSTOMER_DOWNLOAD_TOKEN=0000-1111-2222-3333-4444

Then you can go download the MariaDB enterprise repository:

Bash
wget https://dlm.mariadb.com/enterprise-release-helpers/mariadb_es_repo_setup
chmod +x mariadb_es_repo_setup
./mariadb_es_repo_setup --token="$CUSTOMER_DOWNLOAD_TOKEN" --apply --skip-tools

If you are using the community version, use the command below to connect to the community repositories. (You will need to ensure the Linux Package curl is available):

Bash
yum install -y curl
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --skip-tools

Once the repository is created, install the required MariaDB and Python3 packages:

Bash
yum install -y MariaDB-shared MariaDB-devel python3 python3-devel gcc

You can test that Python is available by checking the version:

Bash
python3 -V

You should see the version of Python returned to the screen:

Bash
Python 3.9.18

Next, we need to get the Python Connector from the MariaDB Downloads page, at the time of writing the latest version is 1.1.9:

Bash
wget -qO- https://dlm.mariadb.com/3700588/Connectors/python/connector-python-1.1.9/mariadb-connector-python-1.1.9.tar.gz | tar xvz -C /usr/local

We need to install the MariaDB Connector, this is done with the use of the Python package manager, pip.

Bash
python3 -m pip install mariadb==1.1.9

You should now have the MariaDB Python Connector installed on your Linux Server.


Now that you have the Python connector installed, you can follow my guide to create a simple Python Application to connect to your MariaDB databases.

Kester Riley

Kester Riley is a Senior Solutions Engineer who leverages his website to establish his brand and build strong business relationships. Through his blog posts, Kester shares his expertise as a consultant, mentor, trainer, and presenter, providing innovative ideas and code examples to empower ambitious professionals.

CentOS (15) Connector (5) Continuous Availability (1) Cooperative Monitoring (3) High Availability (12) Java (3) MariaDB (16) MaxScale (14) Python (2) Replica Rebuild (10) Rocky Linux (15)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.