MySQLdb - MySQLdb - A DB API v2.0 compatible interface to MySQL.
| Use Case | Command | Description |
|---|---|---|
| đ Connect to MySQL | Connect(*args, **kwargs) | Factory function for connections.Connection. |
| đ Escape SQL string | escape_string(s) | Quote SQL-interpreted characters in string s. |
| đ String literal | string_literal(obj) | Convert object to SQL string literal (escaped + quoted). |
| đ Date from ticks | DateFromTicks(ticks) | Convert UNIX ticks into a date instance. |
| â° Time from ticks | TimeFromTicks(ticks) | Convert UNIX ticks into a time instance. |
| đ â° Timestamp from ticks | TimestampFromTicks(ticks) | Convert UNIX ticks into a datetime instance. |
| đ Debug push | debug(s) | DBUG_PUSH with given string (requires debug client library). |
| âšī¸ Client info | get_client_info() | Returns client library version string. |
This package is a wrapper around _mysql, which mostly implements the MySQL C API.
connect() â connects to server
See the C API specification and the MySQL documentation for more info on other items.
For information on how MySQLdb handles type conversion, see the MySQLdb.converters module.
_exceptions_mysqlcompatconnectionsconstants (package)converterscursorsreleasetimesFIELD_TYPEbuiltins.Exception (builtins.BaseException)MySQLdb._exceptions.MySQLErrorMySQLdb._exceptions.ErrorMySQLdb._exceptions.DatabaseErrorMySQLdb._exceptions.DataErrorMySQLdb._exceptions.IntegrityErrorMySQLdb._exceptions.InternalErrorMySQLdb._exceptions.NotSupportedErrorMySQLdb._exceptions.OperationalErrorMySQLdb._exceptions.ProgrammingErrorMySQLdb._exceptions.InterfaceErrorMySQLdb._exceptions.Warning (builtins.Warning, MySQLdb._exceptions.MySQLError)builtins.Warning (builtins.Exception)MySQLdb._exceptions.Warning (same as above)builtins.frozenset (builtins.object)DBAPISetbuiltins.objectdatetime.datedatetime.datetimedatetime.timeclass DBAPISet(builtins.frozenset)
A special type of set for which A == x is true if A is a DBAPISet and x is a member of that set.
Method resolution order: DBAPISet, builtins.frozenset, builtins.object
__eq__(self, other) â Return self==value.__dict__ â dictionary for instance variables (if defined)__hash__ = NoneMethods inherited from builtins.frozenset:
__and__(self, value, /) â Return self&value.__contains__(...) â x.__contains__(y) <==> y in x.__ge__(self, value, /) â Return self>=value.__getattribute__(self, name, /) â Return getattr(self, name).__gt__(self, value, /) â Return self>value.__iter__(self, /) â Implement iter(self).__le__(self, value, /) â Return self<=value.__len__(self, /) â Return len(self).__lt__(self, value, /) â Return self<value.__ne__(self, value, /) â Return self!=value.__or__(self, value, /) â Return self|value.__rand__(self, value, /) â Return value&self.__reduce__(...) â Return state information for pickling.__repr__(self, /) â Return repr(self).__ror__(self, value, /) â Return value|self.__rsub__(self, value, /) â Return value-self.__rxor__(self, value, /) â Return value^self.__sizeof__(...) â S.__sizeof__() -> size of S in memory, in bytes__sub__(self, value, /) â Return self-value.__xor__(self, value, /) â Return self^value.copy(...) â Return a shallow copy of a set.difference(...) â Return the difference of two or more sets as a new set.intersection(...) â Return the intersection of two sets as a new set.isdisjoint(...) â Return True if two sets have a null intersection.issubset(...) â Report whether another set contains this set.issuperset(...) â Report whether this set contains another set.symmetric_difference(...) â Return the symmetric difference of two sets as a new set.union(...) â Return the union of sets as a new set.Class methods inherited from builtins.frozenset:
__class_getitem__(...) â See PEP 585Static methods inherited from builtins.frozenset:
__new__(*args, **kwargs) â Create and return a new object.class DataError(DatabaseError)
Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.
Method resolution order: DataError, DatabaseError, Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass DatabaseError(Error)
Exception raised for errors that are related to the database.
Method resolution order: DatabaseError, Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass date(builtins.object)
date(year, month, day) --> date object
__add__(self, value, /) â Return self+value.__eq__(self, value, /) â Return self==value.__format__(...) â Formats self with strftime.__ge__(self, value, /) â Return self>=value.__getattribute__(self, name, /) â Return getattr(self, name).__gt__(self, value, /) â Return self>value.__hash__(self, /) â Return hash(self).__le__(self, value, /) â Return self<=value.__lt__(self, value, /) â Return self<value.__ne__(self, value, /) â Return self!=value.__radd__(self, value, /) â Return value+self.__reduce__(...) â __reduce__() -> (cls, state)__repr__(self, /) â Return repr(self).__rsub__(self, value, /) â Return value-self.__str__(self, /) â Return str(self).__sub__(self, value, /) â Return self-value.ctime(...) â Return ctime() style string.isocalendar(...) â Return a named tuple containing ISO year, week number, and weekday.isoformat(...) â Return string in ISO 8601 format, YYYY-MM-DD.isoweekday(...) â Return the day of the week (Monday == 1 ... Sunday == 7).replace(...) â Return date with new specified fields.strftime(...) â format -> strftime() style string.timetuple(...) â Return time tuple, compatible with time.localtime().toordinal(...) â Return proleptic Gregorian ordinal.weekday(...) â Return the day of the week (Monday == 0 ... Sunday == 6).Class methods:
fromisocalendar(...) â int, int, int -> Construct a date from ISO year, week number and weekday.fromisoformat(...) â str -> Construct a date from date.isoformat() output.fromordinal(...) â int -> date corresponding to a proleptic Gregorian ordinal.fromtimestamp(timestamp, /) â Create a date from a POSIX timestamp (interpreted as local time).today(...) â Current date: same as self.__class__.fromtimestamp(time.time()).Static methods:
__new__(*args, **kwargs) â Create and return a new object.Data descriptors:
daymonthyearData attributes:
max = datetime.date(9999, 12, 31)min = datetime.date(1, 1, 1)resolution = datetime.timedelta(days=1)class Error(MySQLError)
Exception that is the base class of all other error exceptions (not Warning).
Method resolution order: Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass IntegrityError(DatabaseError)
Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails, duplicate key, etc.
Method resolution order: IntegrityError, DatabaseError, Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass InterfaceError(Error)
Exception raised for errors that are related to the database interface rather than the database itself.
Method resolution order: InterfaceError, Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass InternalError(DatabaseError)
Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc.
Method resolution order: InternalError, DatabaseError, Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass MySQLError(builtins.Exception)
Exception related to operation with MySQL.
Method resolution order: MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass NotSupportedError(DatabaseError)
Exception raised in case a method or database API was used which is not supported by the database, e.g. requesting a .rollback() on a connection that does not support transaction.
Method resolution order: NotSupportedError, DatabaseError, Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass OperationalError(DatabaseError)
Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g. unexpected disconnect, data source name not found, transaction could not be processed, etc.
Method resolution order: OperationalError, DatabaseError, Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass ProgrammingError(DatabaseError)
Exception raised for programming errors, e.g. table not found or already exists, syntax error in SQL statement, wrong number of parameters, etc.
Method resolution order: ProgrammingError, DatabaseError, Error, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsclass time(builtins.object)
time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object
__eq__(self, value, /) â Return self==value.__format__(...) â Formats self with strftime.__ge__(self, value, /) â Return self>=value.__getattribute__(self, name, /) â Return getattr(self, name).__gt__(self, value, /) â Return self>value.__hash__(self, /) â Return hash(self).__le__(self, value, /) â Return self<=value.__lt__(self, value, /) â Return self<value.__ne__(self, value, /) â Return self!=value.__reduce__(...) â __reduce__() -> (cls, state)__reduce_ex__(...) â __reduce_ex__(proto) -> (cls, state)__repr__(self, /) â Return repr(self).__str__(self, /) â Return str(self).dst(...) â Return self.tzinfo.dst(self).isoformat(...) â Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].replace(...) â Return time with new specified fields.strftime(...) â format -> strftime() style string.tzname(...) â Return self.tzinfo.tzname(self).utcoffset(...) â Return self.tzinfo.utcoffset(self).Class methods:
fromisoformat(...) â string -> time from time.isoformat() outputStatic methods:
__new__(*args, **kwargs) â Create and return a new object.Data descriptors:
foldhourmicrosecondminutesecondtzinfoData attributes:
max = datetime.time(23, 59, 59, 999999)min = datetime.time(0, 0)resolution = datetime.timedelta(microseconds=1)class datetime(date)
datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
__add__(self, value, /) â Return self+value.__eq__(self, value, /) â Return self==value.__ge__(self, value, /) â Return self>=value.__getattribute__(self, name, /) â Return getattr(self, name).__gt__(self, value, /) â Return self>value.__hash__(self, /) â Return hash(self).__le__(self, value, /) â Return self<=value.__lt__(self, value, /) â Return self<value.__ne__(self, value, /) â Return self!=value.__radd__(self, value, /) â Return value+self.__reduce__(...) â __reduce__() -> (cls, state)__reduce_ex__(...) â __reduce_ex__(proto) -> (cls, state)__repr__(self, /) â Return repr(self).__rsub__(self, value, /) â Return value-self.__str__(self, /) â Return str(self).__sub__(self, value, /) â Return self-value.astimezone(...) â tz -> convert to local time in new timezone tzctime(...) â Return ctime() style string.date(...) â Return date object with same year, month and day.dst(...) â Return self.tzinfo.dst(self).isoformat(...) â [sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].replace(...) â Return datetime with new specified fields.time(...) â Return time object with same time but with tzinfo=None.timestamp(...) â Return POSIX timestamp as float.timetuple(...) â Return time tuple, compatible with time.localtime().timetz(...) â Return time object with same time and tzinfo.tzname(...) â Return self.tzinfo.tzname(self).utcoffset(...) â Return self.tzinfo.utcoffset(self).utctimetuple(...) â Return UTC time tuple, compatible with time.localtime().Class methods:
combine(...) â date, time -> datetime with same date and time fieldsfromisoformat(...) â string -> datetime from datetime.isoformat() outputfromtimestamp(...) â timestamp[, tz] -> tz's local time from POSIX timestamp.now(tz=None) â Returns new datetime object representing current time local to tz.strptime(...) â string, format -> new datetime parsed from a string.utcfromtimestamp(...) â Construct a naive UTC datetime from a POSIX timestamp.utcnow(...) â Return a new datetime representing UTC day and time.Static methods:
__new__(*args, **kwargs) â Create and return a new object.Data descriptors:
foldhourmicrosecondminutesecondtzinfoData attributes:
max = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)min = datetime.datetime(1, 1, 1, 0, 0)resolution = datetime.timedelta(microseconds=1)Methods inherited from date:
__format__(...) â Formats self with strftime.isocalendar(...) â Return a named tuple containing ISO year, week number, and weekday.isoweekday(...) â Return the day of the week (Monday == 1 ... Sunday == 7).strftime(...) â format -> strftime() style string.toordinal(...) â Return proleptic Gregorian ordinal.weekday(...) â Return the day of the week (Monday == 0 ... Sunday == 6).Class methods inherited from date:
fromisocalendar(...) â int, int, int -> Construct a date from ISO year, week number and weekday.fromordinal(...) â int -> date corresponding to a proleptic Gregorian ordinal.today(...) â Current date or datetime.Data descriptors inherited from date:
daymonthyearclass Warning(builtins.Warning, MySQLError)
Exception raised for important warnings like data truncations while inserting, etc.
Method resolution order: Warning, builtins.Warning, MySQLError, builtins.Exception, builtins.BaseException, builtins.object
__weakref__ â list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) â Initialize self.__new__(*args, **kwargs) â Create and return a new object.Methods inherited from builtins.BaseException:
__delattr__(self, name, /) â Implement delattr(self, name).__getattribute__(self, name, /) â Return getattr(self, name).__reduce__(...) â Helper for pickle.__repr__(self, /) â Return repr(self).__setattr__(self, name, value, /) â Implement setattr(self, name, value).__setstate__(...)__str__(self, /) â Return str(self).with_traceback(...) â Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors inherited from builtins.BaseException:
__cause__ â exception cause__context__ â exception context__dict____suppress_context____traceback__argsBinary(x)Connect(*args, **kwargs) â Factory function for connections.Connection.Connection = Connect(*args, **kwargs) â Factory function for connections.Connection.DateFromTicks(ticks) â Convert UNIX ticks into a date instance.TimeFromTicks(ticks) â Convert UNIX ticks into a time instance.TimestampFromTicks(ticks) â Convert UNIX ticks into a datetime instance.connect = Connect(*args, **kwargs) â Factory function for connections.Connection.debug(...) â Does a DBUG_PUSH with the given string. Requires debug client library.escape(...) â escape(obj, dict) â escape any special characters in object obj using mapping dict.escape_string(...) â escape_string(s) â quote any SQL-interpreted characters in string s. Use connection.escape_string(s) if possible.get_client_info(...) â get_client_info() â Returns a string representing the client library version.string_literal(...) â string_literal(obj) â converts object obj into a SQL string literal (escaped + quoted).BINARY = DBAPISet({249, 250, 251, 252})DATE = DBAPISet({10})NUMBER = DBAPISet({0, 1, 3, 4, 5, 8, 9, 13, 246})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 = 'format'threadsafety = 1version_info = (1, 4, 6, 'final', 0)1.4.6
Inada Naoki <songofacandy AT gmail.com>
/usr/lib/python3/dist-packages/MySQLdb/__init__.py
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-01 18:49 @216.73.216.239
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)