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:
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:
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:
CUSTOMER_DOWNLOAD_TOKEN=0000-1111-2222-3333-4444
Then you can go download the MariaDB enterprise repository:
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):
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:
yum install -y MariaDB-shared MariaDB-devel python3 python3-devel gcc
You can test that Python is available by checking the version:
python3 -V
You should see the version of Python returned to the screen:
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:
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.
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.
Leave a Reply
You must be logged in to post a comment.