pydoc > pymysql

🏷️ NAME

pymysql - PyMySQL: A pure-Python MySQL client library.

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ”Œ Connectpymysql.connect(host='...', user='...', password='...', database='...')Open a MySQL connection
πŸ“‹ Execute querycursor.execute("SELECT * FROM t")Run a SQL statement
πŸ“₯ Fetch one rowcursor.fetchone()Get next result row
πŸ“₯ Fetch all rowscursor.fetchall()Get all remaining rows
πŸ’Ύ Commitconnection.commit()Save transaction changes
βͺ Rollbackconnection.rollback()Undo transaction changes
πŸ”„ Autocommitconnection.autocommit(True)Enable automatic commit
πŸšͺ Closeconnection.close()Close the connection
🐍 Dict cursorpymysql.cursors.DictCursorReturn rows as dictionaries
πŸ›‘οΈ SSL connectionpymysql.connect(..., ssl_ca='ca.pem', ssl_cert='cert.pem', ssl_key='key.pem')Secure connection with certificates

πŸ“– DESCRIPTION

Copyright (c) 2010-2016 PyMySQL contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

πŸ“¦ PACKAGE CONTENTS

πŸ”Œ SUBMODULES

πŸ›οΈ CLASSES

Exception hierarchy:

builtins.Exception(builtins.BaseException)
    pymysql.err.MySQLError
        pymysql.err.Error
            pymysql.err.DatabaseError
                pymysql.err.DataError
                pymysql.err.IntegrityError
                pymysql.err.InternalError
                pymysql.err.NotSupportedError
                pymysql.err.OperationalError
                pymysql.err.ProgrammingError
            pymysql.err.InterfaceError
        pymysql.err.Warning(builtins.Warning, pymysql.err.MySQLError)
builtins.Warning(builtins.Exception)
    pymysql.err.Warning(builtins.Warning, pymysql.err.MySQLError)
builtins.frozenset(builtins.object)
    DBAPISet
builtins.object
    datetime.date
        datetime.datetime
    datetime.time
    pymysql.connections.Connection

🧩 Connection

Connect = class Connection(builtins.object) β€” Alias for pymysql.connections.Connection.

Representation of a socket with a mysql server. The proper way to get an instance is to call connect().

Establish a connection to the MySQL database. Accepts several arguments:

See Connection in the specification.

πŸ› οΈ Connection Methods

πŸ“– Readonly Properties

πŸ“Š Data Descriptors

πŸ“Š Data and Other Attributes

DataError = <class 'pymysql.err.DataError'>
DatabaseError = <class 'pymysql.err.DatabaseError'>
Error = <class 'pymysql.err.Error'>
IntegrityError = <class 'pymysql.err.IntegrityError'>
InterfaceError = <class 'pymysql.err.InterfaceError'>
InternalError = <class 'pymysql.err.InternalError'>
NotSupportedError = <class 'pymysql.err.NotSupportedError'>
OperationalError = <class 'pymysql.err.OperationalError'>
ProgrammingError = <class 'pymysql.err.ProgrammingError'>
Warning = <class 'pymysql.err.Warning'>

🧩 DBAPISet

class DBAPISet(builtins.frozenset)

Methods defined here:

Inherits from frozenset (all set operations).

❌ DataError

class DataError(DatabaseError)

Exception raised for errors due to problems with processed data (division by zero, numeric value out of range, etc.).

Inherits from DatabaseError β†’ Error β†’ MySQLError β†’ Exception.

❌ DatabaseError

class DatabaseError(Error)

Exception raised for errors related to the database.

❌ Error

class Error(MySQLError)

Base class of all error exceptions (not Warning).

❌ IntegrityError

class IntegrityError(DatabaseError)

Exception raised when relational integrity is affected (foreign key check fails, duplicate key, etc.).

❌ InterfaceError

class InterfaceError(Error)

Exception raised for errors related to the database interface rather than the database itself.

❌ InternalError

class InternalError(DatabaseError)

Exception raised when the database encounters an internal error (cursor invalid, transaction out of sync, etc.).

❌ NotSupportedError

class NotSupportedError(DatabaseError)

Exception raised when a method or database API is used that is not supported by the database (e.g., .rollback() on a connection without transactions).

❌ OperationalError

class OperationalError(DatabaseError)

Exception raised for errors related to the database's operation (unexpected disconnect, data source name not found, transaction processing failure, memory allocation error, etc.).

❌ ProgrammingError

class ProgrammingError(DatabaseError)

Exception raised for programming errors (table not found or already exists, syntax error in SQL, wrong number of parameters, etc.).

⚠️ Warning

class Warning(builtins.Warning, MySQLError)

Exception raised for important warnings (data truncations while inserting, etc.).

πŸ•°οΈ Date

Date = class date(builtins.object)
date(year, month, day) β†’ date object

Standard Python datetime.date.

πŸ•°οΈ Time

Time = class time(builtins.object)
time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) β†’ a time object

Standard Python datetime.time.

πŸ•°οΈ Timestamp

Timestamp = class datetime(date)
datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])

Standard Python datetime.datetime.

❌ MySQLError

class MySQLError(builtins.Exception)

Exception related to operation with MySQL.

πŸ› οΈ FUNCTIONS

πŸ“Š DATA

BINARY = DBAPISet({249, 250, 251, 252})
DATE = DBAPISet({10, 14})
NULL = 'NULL'
NUMBER = DBAPISet({0, 1, 3, 4, 5, 8, 9, 13})
ROWID = DBAPISet()
STRING = DBAPISet({253, 254, 247})
TIME = DBAPISet({11})
TIMESTAMP = DBAPISet({12, 7})
__all__ = ['BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date'...]
apilevel = '2.0'
paramstyle = 'pyformat'
threadsafety = 1
version_info = (2, 2, 8, 'final', 1)

πŸ”’ VERSION

2.2.8

πŸ“ FILE

/home/chedong/.local/lib/python3.10/site-packages/pymysql/__init__.py

pymysql
🏷️ NAME πŸš€ Quick Reference πŸ“– DESCRIPTION πŸ“¦ PACKAGE CONTENTS πŸ”Œ SUBMODULES πŸ›οΈ CLASSES
🧩 Connection πŸ› οΈ Connection Methods πŸ“– Readonly Properties πŸ“Š Data Descriptors πŸ“Š Data and Other Attributes 🧩 DBAPISet ❌ DataError ❌ DatabaseError ❌ Error ❌ IntegrityError ❌ InterfaceError ❌ InternalError ❌ NotSupportedError ❌ OperationalError ❌ ProgrammingError ⚠️ Warning πŸ•°οΈ Date πŸ•°οΈ Time πŸ•°οΈ Timestamp ❌ MySQLError
πŸ› οΈ FUNCTIONS πŸ“Š DATA πŸ”’ VERSION πŸ“ FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 11:07 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^