Python Connector for MySQL

Connecting to MySQL - Python Connector for MySQL

Connecting to MySQL

To establish a connection to a MySQL database, import the connector and use the connect() method with your connection parameters.

Step 1. Import the connector

First, import the MySQL connector module:

import devart.mysql as mysql

Step 2. Establish a connection

Call the connect() method and obtain a connection object.

my_connection = mysql.connect(
    Server="your_server",
Database="your_database",
UserId="your_username",
Password="your_password" )

Replace the example values with your actual connection values.

For more information, see Connection parameters.

© 2022-2026 Devart. All Rights Reserved. Request Support Python Connectors Forum Provide Feedback