Python MySQL

Python PostgreSQL

Python SQLite

Python MongoDB

Python Data Access Resources

Python MySQL - Introduction



The Python standard for database interfaces is the Python DB-API. Most Python database interfaces adhere to this standard.

You can choose the right database for your application. Python Database API supports a wide range of database servers such as −

  • GadFly
  • mSQL
  • MySQL
  • PostgreSQL
  • Microsoft SQL Server 2000
  • Informix
  • Interbase
  • Oracle
  • Sybase

Here is the list of available Python database interfaces: Python Database Interfaces and APIs. You must download a separate DB API module for each database you need to access. For example, if you need to access an Oracle database as well as a MySQL database, you must download both the Oracle and the MySQL database modules.

What is mysql-connector-python?

MySQL Python/Connector is an interface for connecting to a MySQL database server from Python. It implements the Python Database API and is built on top of the MySQL.

How do I Install mysql-connector-python?

First of all, you need to make sure you have already installed python in your machine. To do so, open command prompt and type python in it and press Enter. If python is already installed in your system, this command will display its version as shown below −

(myenv) D:\Projects\python\myenv>py
Python 3.14.2 (tags/v3.14.2:df79316, Dec  5 2025, 17:18:21) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Installing mysql-connector-python

Install the mysql driver as shown below−

(myenv) D:\Projects\python\myenv>pip3 install mysql-connector-python
Collecting mysql-connector-python
  Downloading mysql_connector_python-9.5.0-cp314-cp314-win_amd64.whl.metadata (7.7 kB)
Installing collected packages: mysql-connector-python
Successfully installed mysql-connector-python-9.5.0

Verification

To verify the installation of the create a sample python script with the following line in it.

import mysql.connector

If the installation is successful, when you execute it, you should not get any errors −

(myenv) D:\Projects\python\myenv>python test.py
(myenv) D:\Projects\python\myenv>
Advertisements