Currently i’m working on a school project where I have to use MariaDB in a Python3 assignment. I have to build a Python script that connects to a database and put information into it. So said and done, I have created a Python script:
import psutil import socket import mariadb machine = socket.gethostname() memory = psutil.virtual_memory()[2] disk = psutil.disk_usage('/').percent cpu = psutil.cpu_percent() print (machine, memory, disk, cpu) def insert_data(machine, memory, disk, cpu): try: conn = mariadb.connect( user="db_user", password="welkom01", host="192.168.0.2", port=3306, database="gegevens") insert_query = """INSERT INTO info (machine, memory, disk, cpu) VALUES (?, ?, ?, ?);""" verkregen_data = (machine, memory, disk, cpu) cursor = conn.cursor() cursor.execute(insert_query, verkregen_data) cursor.commit() print ("Total", cursor.rowcount, "Data is succesvol in database gegevens.db geschreven") conn.commit() cursor.close() except mariadb.error as error: print(f"Error connecting to MariaDB Platform: {error}") finally: if (conn): conn.close() print("MariaDB connection is closed") insert_data(machine, memory, disk, cpu)
But now my real issue is starting. I’m working with a Linux CentOS 8 system, where I have to put the script on. I have to install the Python3 plugin MariaDB. But when I try to do so: Error msg when trying to install
What I have done so far:
-> Installing Mariadb-server -> Installing the connector from mariaDB’s own website: link to own webside -> Installing the python developer tools: yum -y install openssl-devel bzip2-devel libffi-devel | yum -y groupinstall “Development Tools”
But I can’t figure out what i’m doing wrong… Why it won’t work. So I hope some of you guys can help me out.
Advertisement
Answer
You have to download the latest version of MariaDB Connector/C for Cent OS/8:
$ wget https://downloads.mariadb.com/Connectors/c/connector-c-3.1.10/mariadb-connector-c-3.1.10-centos8-amd64.tar.gz
Then you have to extract the package:
$ tar -xzf mariadb-connector-c-3.1.10-centos8-amd64.tar.gz
Copy the bin, lib and include folders to the right destination (either locally somewhere in your home directory or if it should be available to all users and you have the permissions under e.g. /usr/local.
Make sure that your PATH environment variable contains the bin path. You can check this by calling mariadb_config from your konsole:
$ mariadb_config --cc_version
If successfully installed and path is set it should report 3.1.10
If the library directory is not in default place, make sure that your LD_LIBRARY_PATH environment variable contains the directory of MariaDB Connector/C libraries.
Now you can install MariaDB Connector/Python with
pip3 install mariadb