Registry / database / mysql-python

mysql-python

JSON →
library1.2.5pypypiunverified

mysql-python, also widely known as MySQLdb, is a Python 2.x interface to the popular MySQL database server. The last official release, 1.2.5, dates back to 2014 and primarily supports Python versions 2.4 through 2.7. It adheres to the Python Database API Specification v2.0 (PEP 249). For modern Python 3.x development, this library is considered deprecated, with `mysqlclient` (a actively maintained fork providing a compatible API) and `mysql-connector-python` (Oracle's official pure Python driver) being the recommended alternatives.

pip install mysql-python
INSTALL
IMPORT
SIG · MYSQL-PYTHON
M
mysql-python
databasepythonv1.2.5
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MySQLdb
import MySQLdb
import mysql.connector
mysql-python exposes its functionality via the 'MySQLdb' module, not 'mysql.connector' which belongs to Oracle's 'mysql-connector-python'.

This quickstart demonstrates how to connect to a MySQL database, create a table, insert data, and fetch results using the `MySQLdb` module. Ensure your MySQL server is running and `MYSQL_HOST`, `MYSQL_USER`, `MYSQL_PASSWORD`, and `MYSQL_DATABASE` environment variables are set with appropriate credentials. Remember to commit changes after DDL and DML operations.

import MySQLdb import os try: # Establish a connection to the MySQL server # Note: mysql-python (MySQLdb) primarily supports Python 2.x. # Use 'passwd' for password and 'db' for database name. conn = MySQLdb.connect( host=os.environ.get('MYSQL_HOST', 'localhost'), user=os.environ.get('MYSQL_USER', 'root'), passwd=os.environ.get('MYSQL_PASSWORD', 'password'), db=os.environ.get('MYSQL_DATABASE', 'testdb') ) # Create a cursor object to execute queries cursor = conn.cursor() # Create a table (if it doesn't exist) cursor.execute(""" CREATE TABLE IF NOT EXISTS my_table ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), age INT ) """) conn.commit() # Commit changes for DDL operations # Insert data cursor.execute("INSERT INTO my_table (name, age) VALUES (%s, %s)", ("Alice", 30)) cursor.execute("INSERT INTO my_table (name, age) VALUES (%s, %s)", ("Bob", 24)) conn.commit() # Commit changes for DML operations print(f"Inserted {cursor.rowcount} records.") # Fetch data cursor.execute("SELECT id, name, age FROM my_table") rows = cursor.fetchall() print("\nData in my_table:") for row in rows: print(f"ID: {row[0]}, Name: {row[1]}, Age: {row[2]}") except MySQLdb.Error as e: print(f"Error: {e}") finally: # Close the cursor and connection if 'cursor' in locals() and cursor: cursor.close() if 'conn' in locals() and conn: conn.close() print("\nConnection closed.")
Debug
Known issues
breakingThis library (mysql-python 1.2.5) officially supports Python 2.4-2.7 only. It is not compatible with Python 3.x, and attempts to install or run it on Python 3 will typically fail with `ImportError` or `SyntaxError`.
fix
For Python 3.x, use `mysqlclient` (a fork providing MySQLdb compatibility) or `mysql-connector-python` (Oracle's official driver). Install with `pip install mysqlclient` or `pip install mysql-connector-python` respectively.
affects: All Python 3.x versions
gotchaInstallation often fails due to missing C development headers for MySQL client libraries or Python itself. This is particularly common on fresh OS installations or minimal Docker images.
fix
On Debian/Ubuntu: `sudo apt-get install python-dev libmysqlclient-dev`. On RHEL/CentOS: `sudo yum install python-devel mysql-devel` or `sudo dnf install python-devel mysql-devel`.
affects: All versions on systems without development headers
deprecatedThe `mysql-python` project (MySQLdb) is no longer actively maintained. The last release was in 2014, meaning it receives no new features, performance improvements, or security patches.
fix
Migrate to `mysqlclient` or `mysql-connector-python` for ongoing support, security, and Python 3 compatibility.
affects: All versions (1.2.5 and older)
Upgrade
Version history
1.2.5latest on PyPI · released Jan 2, 2014
Audit
Dependencies
libmysqlclient-devrequiredRequired C development headers for MySQL client libraries.
python-devrequiredRequired Python development headers for compilation.
Agent activity
6 hits · last 30 days
node
4
Resources
mysql-python — pip install mysql-python · libregistry