Connecting to MariaDB via Python

The following example shows how to connect to the MariaDB server via python.

Install pymysql

pip install pymysql

Connect to your server

import pymysql

class MariadbConnection(object):
    def __init__(self): = 'connect host'
        self.port = 4100  # your port
        self.user = 'your user'
        self.passwd = 'user password'
        self.db = 'your connect database name'

    def connect_mariadb(self):
        return pymysql.Connect(, port=self.port, user=self.user, passwd=self.passwd)

    def operate_database(self):
        # example select mysql version
        connect = self.connect_mariadb()
        cursor = connect.cursor()
        cursor.execute("SELECT VERSION()")
        # data = cursor.fetchone()

if _name_ == '__main__':
Copyright © 2021 Cloud Clusters Inc.Revised on 09/29/2021

results matching ""

    No results matching ""