MariaDB Connector/Python

Overview

Python developers can connect to MariaDB SkySQL from their application using MariaDB Connector/Python.

MariaDB Connector/Python can be used with:

  • MariaDB Platform for Transactions

  • MariaDB Platform for Analytics

  • MariaDB Platform for Smart Transactions (HTAP)

  • MariaDB Platform for Distributed SQL

Connector

MariaDB Connector/Python

Supported Versions

1.0 (release notes)

Programming Language

Python

Programming Language Version

Python 3 (CPython 3.6 or later)

API

Python DB API 2.0 (PEP-249)

Supports TLS

Yes

Supports Connection Pools

Yes

License

GNU Lesser General Public License v2.1

API Reference

MariaDB Connector/Python 1.0

MariaDB Connector/Python installation and connection instructions follow. Additional information on MariaDB Connector/Python may be found in the Connector/Python reference.

Installing MariaDB Connector/Python

  1. Ensure that you have Python 3 (CPython 3.6 or later) installed:

    $ python3 --version
    
  2. Install MariaDB Connector/C before you install MariaDB Connector/Python.

  3. Install MariaDB Connector/Python from PyPI using the pip3 command:

    $ pip3 install mariadb
    

Connecting with MariaDB Connector/Python

  1. Determine the connection information for your MariaDB SkySQL database service:

    connect() parameter

    Where to find it

    user

    Default username in the Service Credentials view, or the username you created

    passwd

    Default password in the Service Credentials view, the password you set on the default user, or the password for the user you created

    host

    Fully Qualified Domain Name in the Service Details view

    ssl_ca

    Path to the skysql_chain.pem file containing the "Certificate Authority Chain" (Download)

    port

    Read-Write Port or Read-Only Port in the Service Details view

  2. Load MariaDB Connector/Python into your application by using the import statement.

  3. Connect to the database service by calling the mariadb.connect() function.

    # Module Imports
    import mariadb
    import sys
    
    # Instantiate Connection
    try:
       conn = mariadb.connect(
          user="db_user",
          password="db_user_pwd",
          host="example.skysql.net",
          ssl_ca="/path/to/skysql_chain.pem",
          port=5009)
    
    except mariadb.Error as e:
       print(f"Error connecting to MariaDB Enterprise: {e}")
       sys.exit(1)
    
  4. Execute your script:

    $ python3 mariadb_connection_test.py