Registry /
database / mysql-connector-python-rf
Install & Compatibility
Where this runs
tested against v2.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.059s · 21.1MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 3.0s · import 0.058s · 22MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
mysql.connector
✓ import mysql.connector
This library was a repackaging of the official `mysql-connector-python` at the time, and therefore used the same `mysql.connector` import path.
MySQLConnection
✓ from mysql.connector import MySQLConnection
The core connection class, following DB-API 2.0 standards.
This quickstart demonstrates how to connect to a MySQL database, create a table, insert data, and query data using the `mysql.connector` module. It follows the standard Python DB-API 2.0 pattern and includes basic error handling and proper resource cleanup.
import mysql.connector
import os
host = os.environ.get('MYSQL_HOST', 'localhost')
user = os.environ.get('MYSQL_USER', 'your_user')
password = os.environ.get('MYSQL_PASSWORD', 'your_password')
database = os.environ.get('MYSQL_DATABASE', 'test_db')
try:
# Establish a connection
cnx = mysql.connector.connect(
host=host,
user=user,
password=password,
database=database
)
if cnx.is_connected():
print("Successfully connected to MySQL database.")
cursor = cnx.cursor()
# Create a table (if it doesn't exist)
cursor.execute("CREATE TABLE IF NOT EXISTS users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255))")
cnx.commit()
print("Table 'users' ensured to exist.")
# Insert data
add_user = ("INSERT INTO users (name, email) VALUES (%s, %s)")
data_user = ("John Doe", "john.doe@example.com")
cursor.execute(add_user, data_user)
cnx.commit()
print("Data inserted.")
# Query data
cursor.execute("SELECT id, name, email FROM users")
for (id, name, email) in cursor:
print(f"ID: {id}, Name: {name}, Email: {email}")
else:
print("Failed to connect to MySQL database.")
except mysql.connector.Error as err:
print(f"Error: {err}")
finally:
if 'cnx' in locals() and cnx.is_connected():
cursor.close()
cnx.close()
print("MySQL connection closed.")
Debug
Known issues
breakingThis library (`mysql-connector-python-rf`) is *abandoned and unmaintained*. Its last release was in February 2017, making it incompatible with modern Python versions and potentially containing unpatched security vulnerabilities.fix**DO NOT USE THIS PACKAGE.** Migrate immediately to the official and actively maintained `mysql-connector-python` (install via `pip install mysql-connector-python`).
affects: All versions (2.2.2 and earlier)
deprecatedThe package `mysql-connector-python-rf` was a temporary repackaging to resolve PyPI distribution issues of the official connector. It is severely outdated and not compatible with Python versions beyond 3.3.fixUse the official Oracle-maintained `mysql-connector-python` library. It offers full Python 3 compatibility and active development.
affects: All versions (2.2.2 and earlier)
gotchaForgetting to call `connection.commit()` after executing DML (INSERT, UPDATE, DELETE) statements will result in changes not being saved to the database. This is a common DB-API 2.0 footgun.fixAlways call `connection.commit()` after any operation that modifies the database (e.g., `cnx.commit()` in the quickstart). Alternatively, use a `with` statement for connections if the driver supports auto-commit or transaction management via context.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mysql.connector'
The `mysql-connector-python-rf` package or its official counterpart `mysql-connector-python` is not installed in the active Python environment.
fixEnsure the correct package is installed: `pip install mysql-connector-python-rf` (though highly discouraged) or `pip install mysql-connector-python` (recommended).
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'your_user'@'localhost' (using password: YES)
Incorrect database user credentials (username or password) or insufficient privileges for the specified user.
fixVerify the username, password, and host parameters in `mysql.connector.connect()`. Ensure the MySQL user has the necessary permissions on the target database.
mysql.connector.errors.InterfaceError: 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)
The MySQL server is not running, is not accessible from the client machine, or the connection parameters (host, port) are incorrect.
fixCheck if the MySQL server is running and accessible. Verify the `host` and `port` parameters in the connection string. Ensure no firewall is blocking the connection.
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual...
The SQL query being executed contains a syntax error or is malformed.
fixCarefully review the SQL string passed to `cursor.execute()` for typos, incorrect keywords, or missing clauses. Use parameterized queries (`%s` placeholders) to prevent SQL injection and properly handle special characters.
Upgrade
Version history
2.2.2latest on PyPI · released Feb 4, 2017
Audit
Dependencies
No dependency data recorded yet.