mysql.connector package¶
Subpackages¶
- mysql.connector.django package
- Submodules
- mysql.connector.django.base module
- mysql.connector.django.client module
- mysql.connector.django.compiler module
- mysql.connector.django.creation module
- mysql.connector.django.features module
- mysql.connector.django.introspection module
- mysql.connector.django.operations module
- mysql.connector.django.schema module
- mysql.connector.django.validation module
- Module contents
- mysql.connector.fabric package
- mysql.connector.locales package
Submodules¶
mysql.connector.abstracts module¶
Module gathering all abstract base classes
-
class
mysql.connector.abstracts.MySQLConnectionAbstract(**kwargs)[source]¶ Bases:
mysql.connector.abstracts.MySQLConnectionAbstract,objectAbstract class for classes connecting to a MySQL server
-
autocommit¶ Get whether autocommit is on or off
-
can_consume_results¶ Returns whether to consume results
-
charset¶ Returns the character set for current connection
This property returns the character set name of the current connection. The server is queried when the connection is active. If not connected, the configured character set name is returned.
Returns a string.
-
close()¶ Disconnect from the MySQL server
-
cmd_change_user(username='', password='', database='', charset=33)[source]¶ Change the current logged in user
-
cmd_process_info()[source]¶ Get the process list of the MySQL Server
This method is a placeholder to notify that the PROCESS_INFO command is not supported by raising the NotSupportedError. The command “SHOW PROCESSLIST” should be send using the cmd_query()-method or using the INFORMATION_SCHEMA database.
Raises NotSupportedError exception
-
cmd_query(query, raw=False, buffered=False, raw_as_string=False)[source]¶ Send a query to the MySQL server
-
cmd_stmt_execute(statement_id, data=(), parameters=(), flags=0)[source]¶ Execute a prepared MySQL statement
-
collation¶ Returns the collation for current connection
This property returns the collation name of the current connection. The server is queried when the connection is active. If not connected, the configured collation name is returned.
Returns a string.
-
config(**kwargs)[source]¶ Configure the MySQL Connection
This method allows you to configure the MySQLConnection instance.
Raises on errors.
-
connect(**kwargs)[source]¶ Connect to the MySQL server
This method sets up the connection to the MySQL server. If no arguments are given, it will use the already configured or default values.
-
cursor(buffered=None, raw=None, prepared=None, cursor_class=None, dictionary=None, named_tuple=None)[source]¶ Instantiates and returns a cursor
-
database¶ Get the current database
-
get_server_info()[source]¶ Get the original MySQL version information
This method returns the original MySQL server as text. If not previously connected, it will return None.
Returns a string or None.
-
get_server_version()[source]¶ Get the MySQL version
This method returns the MySQL server version as a tuple. If not previously connected, it will return None.
Returns a tuple or None.
-
get_warnings¶ Get whether this connection retrieves warnings automatically
This method returns whether this connection retrieves warnings automatically.
Returns True, or False when warnings are not retrieved.
-
in_transaction¶ MySQL session has started a transaction
-
python_charset¶ Returns the Python character set for current connection
This property returns the character set name of the current connection. Note that, unlike property charset, this checks if the previously set character set is supported by Python and if not, it returns the equivalent character set that Python supports.
Returns a string.
-
raise_on_warnings¶ Get whether this connection raises an error on warnings
This method returns whether this connection will raise errors when MySQL reports warnings.
Returns True or False.
-
reconnect(attempts=1, delay=0)[source]¶ Attempt to reconnect to the MySQL server
The argument attempts should be the number of times a reconnect is tried. The delay argument is the number of seconds to wait between each retry.
You may want to set the number of attempts higher and use delay when you expect the MySQL server to be down for maintenance or when you expect the network to be temporary unavailable.
Raises InterfaceError on errors.
-
reset_session(user_variables=None, session_variables=None)[source]¶ Clears the current active session
This method resets the session state, if the MySQL server is 5.7.3 or later active session will be reset without re-authenticating. For other server versions session will be reset by re-authenticating.
It is possible to provide a sequence of variables and their values to be set after clearing the session. This is possible for both user defined variables and session variables. This method takes two arguments user_variables and session_variables which are dictionaries.
Raises OperationalError if not connected, InternalError if there are unread results and InterfaceError on errors.
-
server_host¶ MySQL server IP address or name
-
server_port¶ MySQL server TCP/IP port
-
set_charset_collation(charset=None, collation=None)[source]¶ Sets the character set and collation for the current connection
This method sets the character set and collation to be used for the current connection. The charset argument can be either the name of a character set as a string, or the numerical equivalent as defined in constants.CharacterSet.
When the collation is not given, the default will be looked up and used.
For example, the following will set the collation for the latin1 character set to latin1_general_ci:
set_charset(‘latin1’,’latin1_general_ci’)
-
set_client_flags(flags)[source]¶ Set the client flags
The flags-argument can be either an int or a list (or tuple) of ClientFlag-values. If it is an integer, it will set client_flags to flags as is. If flags is a list (or tuple), each flag will be set or unset when it’s negative.
set_client_flags([ClientFlag.FOUND_ROWS,-ClientFlag.LONG_FLAG])
Raises ProgrammingError when the flags argument is not a set or an integer bigger than 0.
Returns self.client_flags
-
set_converter_class(convclass)[source]¶ Set the converter class to be used. This should be a class overloading methods and members of conversion.MySQLConverter.
-
set_login(username=None, password=None)[source]¶ Set login information for MySQL
Set the username and/or password for the user connecting to the MySQL Server.
-
set_unicode(value=True)[source]¶ Toggle unicode mode
Set whether we return string fields as unicode or not. Default is True.
-
sql_mode¶ Get the SQL mode
-
start_transaction(consistent_snapshot=False, isolation_level=None, readonly=None)[source]¶ Start a transaction
This method explicitly starts a transaction sending the START TRANSACTION statement to the MySQL server. You can optionally set whether there should be a consistent snapshot, which isolation level you need or which access mode i.e. READ ONLY or READ WRITE.
For example, to start a transaction with isolation level SERIALIZABLE, you would do the following:
>>> cnx = mysql.connector.connect(..) >>> cnx.start_transaction(isolation_level='SERIALIZABLE')
Raises ProgrammingError when a transaction is already in progress and when ValueError when isolation_level specifies an Unknown level.
-
time_zone¶ Get the current time zone
-
unix_socket¶ MySQL Unix socket file location
-
unread_result¶ Get whether there is an unread result
This method is used by cursors to check whether another cursor still needs to retrieve its result set.
Returns True, or False when there is no unread result.
-
user¶ User used while connecting to MySQL
-
-
class
mysql.connector.abstracts.MySQLCursorAbstract[source]¶ Bases:
mysql.connector.abstracts.MySQLCursorAbstract,objectAbstract cursor class
Abstract class defining cursor class with method and members required by the Python Database API Specification v2.0.
-
callproc(procname, args=())[source]¶ Calls a stored procedure with the given arguments
The arguments will be set during this session, meaning they will be called like _<procname>__arg<nr> where <nr> is an enumeration (+1) of the arguments.
- Coding Example:
1) Defining the Stored Routine in MySQL: CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT) BEGIN
SET pProd := pFac1 * pFac2;END
2) Executing in Python: args = (5,5,0) # 0 is to hold pprod cursor.callproc(‘multiply’, args) print(cursor.fetchone())
Does not return a value, but a result set will be available when the CALL-statement execute successfully. Raises exceptions when something is wrong.
-
description¶ Returns description of columns in a result
This property returns a list of tuples describing the columns in in a result set. A tuple is described as follows:
(column_name, type, None, None, None, None, null_ok, column_flags) # Addition to PEP-249 specs
Returns a list of tuples.
-
execute(operation, params=(), multi=False)[source]¶ Executes the given operation
Executes the given operation substituting any markers with the given parameters.
- For example, getting all rows where id is 5:
- cursor.execute(“SELECT * FROM t1 WHERE id = %s”, (5,))
The multi argument should be set to True when executing multiple statements in one operation. If not set and multiple results are found, an InterfaceError will be raised.
If warnings where generated, and connection.get_warnings is True, then self._warnings will be a list containing these warnings.
Returns an iterator when multi is True, otherwise None.
-
executemany(operation, seqparams)[source]¶ Execute the given operation multiple times
The executemany() method will execute the operation iterating over the list of parameters in seq_params.
Example: Inserting 3 new employees and their phone number
- data = [
- (‘Jane’,‘555-001’), (‘Joe’, ‘555-001’), (‘John’, ‘555-003’) ]
stmt = “INSERT INTO employees (name, phone) VALUES (‘%s’,’%s’)” cursor.executemany(stmt, data)
INSERT statements are optimized by batching the data, that is using the MySQL multiple rows syntax.
Results are discarded. If they are needed, consider looping over data using the execute() method.
-
fetchmany(size=1)[source]¶ Returns the next set of rows of a query result, returning a list of tuples. When no more rows are available, it returns an empty list.
The number of rows returned can be specified using the size argument, which defaults to one
-
lastrowid¶ Returns the value generated for an AUTO_INCREMENT column
Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement or None when there is no such value available.
Returns a long value or None.
-
rowcount¶ Returns the number of rows produced or affected
This property returns the number of rows produced by queries such as a SELECT, or affected rows when executing DML statements like INSERT or UPDATE.
Note that for non-buffered cursors it is impossible to know the number of rows produced before having fetched them all. For those, the number of rows will be -1 right after execution, and incremented when fetching rows.
Returns an integer.
-
mysql.connector.authentication module¶
Implementing support for MySQL Authentication Plugins
-
class
mysql.connector.authentication.BaseAuthPlugin(auth_data, username=None, password=None, database=None, ssl_enabled=False)[source]¶ Bases:
objectBase class for authentication plugins
Classes inheriting from BaseAuthPlugin should implement the method prepare_password(). When instantiating, auth_data argument is required. The username, password and database are optional. The ssl_enabled argument can be used to tell the plugin whether SSL is active or not.
The method auth_response() method is used to retrieve the password which was prepared by prepare_password().
-
auth_response()[source]¶ Returns the prepared password to send to MySQL
Raises InterfaceError on errors. For example, when SSL is required by not enabled.
Returns str
-
plugin_name= ''¶
-
prepare_password()[source]¶ Prepares and returns password to be send to MySQL
This method needs to be implemented by classes inheriting from this class. It is used by the auth_response() method.
Raises NotImplementedError.
-
requires_ssl= False¶
-
-
class
mysql.connector.authentication.MySQLClearPasswordAuthPlugin(auth_data, username=None, password=None, database=None, ssl_enabled=False)[source]¶ Bases:
mysql.connector.authentication.BaseAuthPluginClass implementing the MySQL Clear Password authentication plugin
-
plugin_name= 'mysql_clear_password'¶
-
requires_ssl= True¶
-
-
class
mysql.connector.authentication.MySQLNativePasswordAuthPlugin(auth_data, username=None, password=None, database=None, ssl_enabled=False)[source]¶ Bases:
mysql.connector.authentication.BaseAuthPluginClass implementing the MySQL Native Password authentication plugin
-
plugin_name= 'mysql_native_password'¶
-
requires_ssl= False¶
-
-
class
mysql.connector.authentication.MySQLSHA256PasswordAuthPlugin(auth_data, username=None, password=None, database=None, ssl_enabled=False)[source]¶ Bases:
mysql.connector.authentication.BaseAuthPluginClass implementing the MySQL SHA256 authentication plugin
Note that encrypting using RSA is not supported since the Python Standard Library does not provide this OpenSSL functionality.
-
plugin_name= 'sha256_password'¶
-
requires_ssl= True¶
-
-
mysql.connector.authentication.get_auth_plugin(plugin_name)[source]¶ Return authentication class based on plugin name
This function returns the class for the authentication plugin plugin_name. The returned class is a subclass of BaseAuthPlugin.
Raises errors.NotSupportedError when plugin_name is not supported.
Returns subclass of BaseAuthPlugin.
mysql.connector.catch23 module¶
Python v2 to v3 migration module
mysql.connector.charsets module¶
mysql.connector.connection module¶
Implementing communication with MySQL servers.
-
class
mysql.connector.connection.MySQLConnection(*args, **kwargs)[source]¶ Bases:
mysql.connector.abstracts.MySQLConnectionAbstractConnection to a MySQL Server
-
cmd_change_user(username='', password='', database='', charset=33)[source]¶ Change the current logged in user
This method allows to change the current logged in user information. The result is a dictionary with OK packet information.
Returns a dict()
-
cmd_debug()[source]¶ Send the DEBUG command
This method sends the DEBUG command to the MySQL server, which requires the MySQL user to have SUPER privilege. The output will go to the MySQL server error log and the result of this method is a dictionary with EOF packet information.
Returns a dict()
-
cmd_init_db(database)[source]¶ Change the current database
This method changes the current (default) database by sending the INIT_DB command. The result is a dictionary containing the OK packet information.
Returns a dict()
-
cmd_ping()[source]¶ Send the PING command
This method sends the PING command to the MySQL server. It is used to check if the the connection is still valid. The result of this method is dictionary with OK packet information.
Returns a dict()
-
cmd_process_kill(mysql_pid)[source]¶ Kill a MySQL process
This method send the PROCESS_KILL command to the server along with the process ID. The result is a dictionary with the OK packet information.
Returns a dict()
-
cmd_query(query, raw=False, buffered=False, raw_as_string=False)[source]¶ Send a query to the MySQL server
This method send the query to the MySQL server and returns the result.
If there was a text result, a tuple will be returned consisting of the number of columns and a list containing information about these columns.
When the query doesn’t return a text result, the OK or EOF packet information as dictionary will be returned. In case the result was an error, exception errors.Error will be raised.
Returns a tuple()
-
cmd_query_iter(statements)[source]¶ Send one or more statements to the MySQL server
Similar to the cmd_query method, but instead returns a generator object to iterate through results. It sends the statements to the MySQL server and through the iterator you can get the results.
statement = ‘SELECT 1; INSERT INTO t1 VALUES (); SELECT 2’ for result in cnx.cmd_query(statement, iterate=True):
- if ‘columns’ in result:
- columns = result[‘columns’] rows = cnx.get_rows()
- else:
- # do something useful with INSERT result
Returns a generator.
-
cmd_quit()[source]¶ Close the current connection with the server
This method sends the QUIT command to the MySQL server, closing the current connection. Since the no response can be returned to the client, cmd_quit() will return the packet it send.
Returns a str()
-
cmd_refresh(options)[source]¶ Send the Refresh command to the MySQL server
This method sends the Refresh command to the MySQL server. The options argument should be a bitwise value using constants.RefreshOption. Usage example:
RefreshOption = mysql.connector.RefreshOption refresh = RefreshOption.LOG | RefreshOption.THREADS cnx.cmd_refresh(refresh)The result is a dictionary with the OK packet information.
Returns a dict()
-
cmd_reset_connection()[source]¶ Resets the session state without re-authenticating
Works only for MySQL server 5.7.3 or later. The result is a dictionary with OK packet information.
Returns a dict()
-
cmd_shutdown(shutdown_type=None)[source]¶ Shut down the MySQL Server
This method sends the SHUTDOWN command to the MySQL server and is only possible if the current user has SUPER privileges. The result is a dictionary containing the OK packet information.
Note: Most applications and scripts do not the SUPER privilege.
Returns a dict()
-
cmd_statistics()[source]¶ Send the statistics command to the MySQL Server
This method sends the STATISTICS command to the MySQL server. The result is a dictionary with various statistical information.
Returns a dict()
-
cmd_stmt_close(statement_id)[source]¶ Deallocate a prepared MySQL statement
This method deallocates the prepared statement using the statement_id. Note that the MySQL server does not return anything.
-
cmd_stmt_execute(statement_id, data=(), parameters=(), flags=0)[source]¶ Execute a prepared MySQL statement
-
cmd_stmt_prepare(statement)[source]¶ Prepare a MySQL statement
This method will send the PREPARE command to MySQL together with the given statement.
Returns a dict()
-
cmd_stmt_reset(statement_id)[source]¶ Reset data for prepared statement sent as long data
The result is a dictionary with OK packet information.
Returns a dict()
-
cmd_stmt_send_long_data(statement_id, param_id, data)[source]¶ Send data for a column
This methods send data for a column (for example BLOB) for statement identified by statement_id. The param_id indicate which parameter the data belongs too. The data argument should be a file-like object.
Since MySQL does not send anything back, no error is raised. When the MySQL server is not reachable, an OperationalError is raised.
cmd_stmt_send_long_data should be called before cmd_stmt_execute.
The total bytes send is returned.
Returns int.
-
connection_id¶ MySQL connection ID
-
cursor(buffered=None, raw=None, prepared=None, cursor_class=None, dictionary=None, named_tuple=None)[source]¶ Instantiates and returns a cursor
By default, MySQLCursor is returned. Depending on the options while connecting, a buffered and/or raw cursor is instantiated instead. Also depending upon the cursor options, rows can be returned as dictionary or named tuple.
Dictionary and namedtuple based cursors are available with buffered output but not raw.
It is possible to also give a custom cursor through the cursor_class parameter, but it needs to be a subclass of mysql.connector.cursor.CursorBase.
Raises ProgrammingError when cursor_class is not a subclass of CursorBase. Raises ValueError when cursor is not available.
Returns a cursor-object
-
database¶ Get the current database
-
disconnect()¶ Disconnect from the MySQL server
-
get_row(binary=False, columns=None)[source]¶ Get the next rows returned by the MySQL server
This method gets one row from the result set after sending, for example, the query command. The result is a tuple consisting of the row and the EOF packet. If no row was available in the result set, the row data will be None.
Returns a tuple.
-
get_rows(count=None, binary=False, columns=None)[source]¶ Get all rows returned by the MySQL server
This method gets all rows returned by the MySQL server after sending, for example, the query command. The result is a tuple consisting of a list of rows and the EOF packet.
Returns a tuple()
-
in_transaction¶ MySQL session has started a transaction
-
is_connected()[source]¶ Reports whether the connection to MySQL Server is available
This method checks whether the connection to MySQL is available. It is similar to ping(), but unlike the ping()-method, either True or False is returned and no exception is raised.
Returns True or False.
-
ping(reconnect=False, attempts=1, delay=0)[source]¶ Check availability of the MySQL server
When reconnect is set to True, one or more attempts are made to try to reconnect to the MySQL server using the reconnect()-method.
delay is the number of seconds to wait between each retry.
When the connection is not available, an InterfaceError is raised. Use the is_connected()-method if you just want to check the connection without raising an error.
Raises InterfaceError on errors.
-
reconnect(attempts=1, delay=0)[source]¶ Attempt to reconnect to the MySQL server
The argument attempts should be the number of times a reconnect is tried. The delay argument is the number of seconds to wait between each retry.
You may want to set the number of attempts higher and use delay when you expect the MySQL server to be down for maintenance or when you expect the network to be temporary unavailable.
Raises InterfaceError on errors.
-
reset_session(user_variables=None, session_variables=None)[source]¶ Clears the current active session
This method resets the session state, if the MySQL server is 5.7.3 or later active session will be reset without re-authenticating. For other server versions session will be reset by re-authenticating.
It is possible to provide a sequence of variables and their values to be set after clearing the session. This is possible for both user defined variables and session variables. This method takes two arguments user_variables and session_variables which are dictionaries.
Raises OperationalError if not connected, InternalError if there are unread results and InterfaceError on errors.
-
mysql.connector.connection_cext module¶
mysql.connector.constants module¶
Various MySQL constants and character sets
-
class
mysql.connector.constants.CharacterSet[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL supported character sets and collations
List of character sets with their collations supported by MySQL. This maps to the character set we get from the server within the handshake packet.
The list is hardcode so we avoid a database query when getting the name of the used character set or collation.
-
desc= [None, ('big5', 'big5_chinese_ci', True), ('latin2', 'latin2_czech_cs', False), ('dec8', 'dec8_swedish_ci', True), ('cp850', 'cp850_general_ci', True), ('latin1', 'latin1_german1_ci', False), ('hp8', 'hp8_english_ci', True), ('koi8r', 'koi8r_general_ci', True), ('latin1', 'latin1_swedish_ci', True), ('latin2', 'latin2_general_ci', True), ('swe7', 'swe7_swedish_ci', True), ('ascii', 'ascii_general_ci', True), ('ujis', 'ujis_japanese_ci', True), ('sjis', 'sjis_japanese_ci', True), ('cp1251', 'cp1251_bulgarian_ci', False), ('latin1', 'latin1_danish_ci', False), ('hebrew', 'hebrew_general_ci', True), None, ('tis620', 'tis620_thai_ci', True), ('euckr', 'euckr_korean_ci', True), ('latin7', 'latin7_estonian_cs', False), ('latin2', 'latin2_hungarian_ci', False), ('koi8u', 'koi8u_general_ci', True), ('cp1251', 'cp1251_ukrainian_ci', False), ('gb2312', 'gb2312_chinese_ci', True), ('greek', 'greek_general_ci', True), ('cp1250', 'cp1250_general_ci', True), ('latin2', 'latin2_croatian_ci', False), ('gbk', 'gbk_chinese_ci', True), ('cp1257', 'cp1257_lithuanian_ci', False), ('latin5', 'latin5_turkish_ci', True), ('latin1', 'latin1_german2_ci', False), ('armscii8', 'armscii8_general_ci', True), ('utf8', 'utf8_general_ci', True), ('cp1250', 'cp1250_czech_cs', False), ('ucs2', 'ucs2_general_ci', True), ('cp866', 'cp866_general_ci', True), ('keybcs2', 'keybcs2_general_ci', True), ('macce', 'macce_general_ci', True), ('macroman', 'macroman_general_ci', True), ('cp852', 'cp852_general_ci', True), ('latin7', 'latin7_general_ci', True), ('latin7', 'latin7_general_cs', False), ('macce', 'macce_bin', False), ('cp1250', 'cp1250_croatian_ci', False), ('utf8mb4', 'utf8mb4_general_ci', True), ('utf8mb4', 'utf8mb4_bin', False), ('latin1', 'latin1_bin', False), ('latin1', 'latin1_general_ci', False), ('latin1', 'latin1_general_cs', False), ('cp1251', 'cp1251_bin', False), ('cp1251', 'cp1251_general_ci', True), ('cp1251', 'cp1251_general_cs', False), ('macroman', 'macroman_bin', False), ('utf16', 'utf16_general_ci', True), ('utf16', 'utf16_bin', False), ('utf16le', 'utf16le_general_ci', True), ('cp1256', 'cp1256_general_ci', True), ('cp1257', 'cp1257_bin', False), ('cp1257', 'cp1257_general_ci', True), ('utf32', 'utf32_general_ci', True), ('utf32', 'utf32_bin', False), ('utf16le', 'utf16le_bin', False), ('binary', 'binary', True), ('armscii8', 'armscii8_bin', False), ('ascii', 'ascii_bin', False), ('cp1250', 'cp1250_bin', False), ('cp1256', 'cp1256_bin', False), ('cp866', 'cp866_bin', False), ('dec8', 'dec8_bin', False), ('greek', 'greek_bin', False), ('hebrew', 'hebrew_bin', False), ('hp8', 'hp8_bin', False), ('keybcs2', 'keybcs2_bin', False), ('koi8r', 'koi8r_bin', False), ('koi8u', 'koi8u_bin', False), None, ('latin2', 'latin2_bin', False), ('latin5', 'latin5_bin', False), ('latin7', 'latin7_bin', False), ('cp850', 'cp850_bin', False), ('cp852', 'cp852_bin', False), ('swe7', 'swe7_bin', False), ('utf8', 'utf8_bin', False), ('big5', 'big5_bin', False), ('euckr', 'euckr_bin', False), ('gb2312', 'gb2312_bin', False), ('gbk', 'gbk_bin', False), ('sjis', 'sjis_bin', False), ('tis620', 'tis620_bin', False), ('ucs2', 'ucs2_bin', False), ('ujis', 'ujis_bin', False), ('geostd8', 'geostd8_general_ci', True), ('geostd8', 'geostd8_bin', False), ('latin1', 'latin1_spanish_ci', False), ('cp932', 'cp932_japanese_ci', True), ('cp932', 'cp932_bin', False), ('eucjpms', 'eucjpms_japanese_ci', True), ('eucjpms', 'eucjpms_bin', False), ('cp1250', 'cp1250_polish_ci', False), None, ('utf16', 'utf16_unicode_ci', False), ('utf16', 'utf16_icelandic_ci', False), ('utf16', 'utf16_latvian_ci', False), ('utf16', 'utf16_romanian_ci', False), ('utf16', 'utf16_slovenian_ci', False), ('utf16', 'utf16_polish_ci', False), ('utf16', 'utf16_estonian_ci', False), ('utf16', 'utf16_spanish_ci', False), ('utf16', 'utf16_swedish_ci', False), ('utf16', 'utf16_turkish_ci', False), ('utf16', 'utf16_czech_ci', False), ('utf16', 'utf16_danish_ci', False), ('utf16', 'utf16_lithuanian_ci', False), ('utf16', 'utf16_slovak_ci', False), ('utf16', 'utf16_spanish2_ci', False), ('utf16', 'utf16_roman_ci', False), ('utf16', 'utf16_persian_ci', False), ('utf16', 'utf16_esperanto_ci', False), ('utf16', 'utf16_hungarian_ci', False), ('utf16', 'utf16_sinhala_ci', False), ('utf16', 'utf16_german2_ci', False), ('utf16', 'utf16_croatian_ci', False), ('utf16', 'utf16_unicode_520_ci', False), ('utf16', 'utf16_vietnamese_ci', False), None, None, None, ('ucs2', 'ucs2_unicode_ci', False), ('ucs2', 'ucs2_icelandic_ci', False), ('ucs2', 'ucs2_latvian_ci', False), ('ucs2', 'ucs2_romanian_ci', False), ('ucs2', 'ucs2_slovenian_ci', False), ('ucs2', 'ucs2_polish_ci', False), ('ucs2', 'ucs2_estonian_ci', False), ('ucs2', 'ucs2_spanish_ci', False), ('ucs2', 'ucs2_swedish_ci', False), ('ucs2', 'ucs2_turkish_ci', False), ('ucs2', 'ucs2_czech_ci', False), ('ucs2', 'ucs2_danish_ci', False), ('ucs2', 'ucs2_lithuanian_ci', False), ('ucs2', 'ucs2_slovak_ci', False), ('ucs2', 'ucs2_spanish2_ci', False), ('ucs2', 'ucs2_roman_ci', False), ('ucs2', 'ucs2_persian_ci', False), ('ucs2', 'ucs2_esperanto_ci', False), ('ucs2', 'ucs2_hungarian_ci', False), ('ucs2', 'ucs2_sinhala_ci', False), ('ucs2', 'ucs2_german2_ci', False), ('ucs2', 'ucs2_croatian_ci', False), ('ucs2', 'ucs2_unicode_520_ci', False), ('ucs2', 'ucs2_vietnamese_ci', False), None, None, None, None, None, None, None, ('ucs2', 'ucs2_general_mysql500_ci', False), ('utf32', 'utf32_unicode_ci', False), ('utf32', 'utf32_icelandic_ci', False), ('utf32', 'utf32_latvian_ci', False), ('utf32', 'utf32_romanian_ci', False), ('utf32', 'utf32_slovenian_ci', False), ('utf32', 'utf32_polish_ci', False), ('utf32', 'utf32_estonian_ci', False), ('utf32', 'utf32_spanish_ci', False), ('utf32', 'utf32_swedish_ci', False), ('utf32', 'utf32_turkish_ci', False), ('utf32', 'utf32_czech_ci', False), ('utf32', 'utf32_danish_ci', False), ('utf32', 'utf32_lithuanian_ci', False), ('utf32', 'utf32_slovak_ci', False), ('utf32', 'utf32_spanish2_ci', False), ('utf32', 'utf32_roman_ci', False), ('utf32', 'utf32_persian_ci', False), ('utf32', 'utf32_esperanto_ci', False), ('utf32', 'utf32_hungarian_ci', False), ('utf32', 'utf32_sinhala_ci', False), ('utf32', 'utf32_german2_ci', False), ('utf32', 'utf32_croatian_ci', False), ('utf32', 'utf32_unicode_520_ci', False), ('utf32', 'utf32_vietnamese_ci', False), None, None, None, None, None, None, None, None, ('utf8', 'utf8_unicode_ci', False), ('utf8', 'utf8_icelandic_ci', False), ('utf8', 'utf8_latvian_ci', False), ('utf8', 'utf8_romanian_ci', False), ('utf8', 'utf8_slovenian_ci', False), ('utf8', 'utf8_polish_ci', False), ('utf8', 'utf8_estonian_ci', False), ('utf8', 'utf8_spanish_ci', False), ('utf8', 'utf8_swedish_ci', False), ('utf8', 'utf8_turkish_ci', False), ('utf8', 'utf8_czech_ci', False), ('utf8', 'utf8_danish_ci', False), ('utf8', 'utf8_lithuanian_ci', False), ('utf8', 'utf8_slovak_ci', False), ('utf8', 'utf8_spanish2_ci', False), ('utf8', 'utf8_roman_ci', False), ('utf8', 'utf8_persian_ci', False), ('utf8', 'utf8_esperanto_ci', False), ('utf8', 'utf8_hungarian_ci', False), ('utf8', 'utf8_sinhala_ci', False), ('utf8', 'utf8_german2_ci', False), ('utf8', 'utf8_croatian_ci', False), ('utf8', 'utf8_unicode_520_ci', False), ('utf8', 'utf8_vietnamese_ci', False), None, None, None, None, None, None, None, ('utf8', 'utf8_general_mysql500_ci', False), ('utf8mb4', 'utf8mb4_unicode_ci', False), ('utf8mb4', 'utf8mb4_icelandic_ci', False), ('utf8mb4', 'utf8mb4_latvian_ci', False), ('utf8mb4', 'utf8mb4_romanian_ci', False), ('utf8mb4', 'utf8mb4_slovenian_ci', False), ('utf8mb4', 'utf8mb4_polish_ci', False), ('utf8mb4', 'utf8mb4_estonian_ci', False), ('utf8mb4', 'utf8mb4_spanish_ci', False), ('utf8mb4', 'utf8mb4_swedish_ci', False), ('utf8mb4', 'utf8mb4_turkish_ci', False), ('utf8mb4', 'utf8mb4_czech_ci', False), ('utf8mb4', 'utf8mb4_danish_ci', False), ('utf8mb4', 'utf8mb4_lithuanian_ci', False), ('utf8mb4', 'utf8mb4_slovak_ci', False), ('utf8mb4', 'utf8mb4_spanish2_ci', False), ('utf8mb4', 'utf8mb4_roman_ci', False), ('utf8mb4', 'utf8mb4_persian_ci', False), ('utf8mb4', 'utf8mb4_esperanto_ci', False), ('utf8mb4', 'utf8mb4_hungarian_ci', False), ('utf8mb4', 'utf8mb4_sinhala_ci', False), ('utf8mb4', 'utf8mb4_german2_ci', False), ('utf8mb4', 'utf8mb4_croatian_ci', False), ('utf8mb4', 'utf8mb4_unicode_520_ci', False), ('utf8mb4', 'utf8mb4_vietnamese_ci', False), ('gb18030', 'gb18030_chinese_ci', True), ('gb18030', 'gb18030_bin', False), ('gb18030', 'gb18030_unicode_520_ci', False)]¶
-
classmethod
get_charset_info(charset=None, collation=None)[source]¶ Get character set information using charset name and/or collation
Retrieves character set and collation information given character set name and/or a collation name. If charset is an integer, it will look up the character set based on the MySQL’s ID. For example:
get_charset_info(‘utf8’,None) get_charset_info(collation=’utf8_general_ci’) get_charset_info(47)Raises ProgrammingError when character set is not supported.
Returns a tuple with (id, characterset name, collation)
-
classmethod
get_default_collation(charset)[source]¶ Retrieves the default collation for given character set
Raises ProgrammingError when character set is not supported.
Returns list (collation, charset, index)
-
classmethod
get_desc(setid)[source]¶ Retrieves character set information as string using an ID
Retrieves character set and collation information based on the given MySQL ID.
Returns a tuple.
-
classmethod
get_info(setid)[source]¶ Retrieves character set information as tuple using an ID
Retrieves character set and collation information based on the given MySQL ID.
Raises ProgrammingError when character set is not supported.
Returns a tuple.
-
classmethod
get_supported()[source]¶ Retrieves a list with names of all supproted character sets
Returns a tuple.
-
slash_charsets= (1, 13, 28, 84, 87, 88)¶
-
-
class
mysql.connector.constants.ClientFlag[source]¶ Bases:
mysql.connector.constants._FlagsMySQL Client Flags
Client options as found in the MySQL sources mysql-src/include/mysql_com.h
-
CAN_HANDLE_EXPIRED_PASSWORDS= 4194304¶
-
COMPRESS= 32¶
-
CONNECT_ARGS= 1048576¶
-
CONNECT_WITH_DB= 8¶
-
DEPRECATE_EOF= 16777216¶
-
FOUND_ROWS= 2¶
-
IGNORE_SIGPIPE= 4096¶
-
IGNORE_SPACE= 256¶
-
INTERACTIVE= 1024¶
-
LOCAL_FILES= 128¶
-
LONG_FLAG= 4¶
-
LONG_PASSWD= 1¶
-
MULTI_RESULTS= 131072¶
-
MULTI_STATEMENTS= 65536¶
-
NO_SCHEMA= 16¶
-
ODBC= 64¶
-
PLUGIN_AUTH= 524288¶
-
PLUGIN_AUTH_LENENC_CLIENT_DATA= 2097152¶
-
PROTOCOL_41= 512¶
-
PS_MULTI_RESULTS= 262144¶
-
REMEMBER_OPTIONS= 2147483648¶
-
RESERVED= 16384¶
-
SECURE_CONNECTION= 32768¶
-
SESION_TRACK= 8388608¶
-
SSL= 2048¶
-
SSL_VERIFY_SERVER_CERT= 1073741824¶
-
TRANSACTIONS= 8192¶
-
default= [1, 4, 8, 512, 8192, 32768, 65536, 131072, 128]¶
-
desc= {'CAN_HANDLE_EXPIRED_PASSWORDS': (4194304, "Don't close the connection for a connection with expired password"), 'COMPRESS': (32, 'Can use compression protocol'), 'CONNECT_ARGS': (1048576, 'Client supports connection attributes'), 'CONNECT_WITH_DB': (8, 'One can specify db on connect'), 'DEPRECATE_EOF': (16777216, 'Client no longer needs EOF packet'), 'FOUND_ROWS': (2, 'Found instead of affected rows'), 'IGNORE_SIGPIPE': (4096, 'IGNORE sigpipes'), 'IGNORE_SPACE': (256, "Ignore spaces before ''"), 'INTERACTIVE': (1024, 'This is an interactive client'), 'LOCAL_FILES': (128, 'Can use LOAD DATA LOCAL'), 'LONG_FLAG': (4, 'Get all column flags'), 'LONG_PASSWD': (1, 'New more secure passwords'), 'MULTI_RESULTS': (131072, 'Enable/disable multi-results'), 'MULTI_STATEMENTS': (65536, 'Enable/disable multi-stmt support'), 'NO_SCHEMA': (16, "Don't allow database.table.column"), 'ODBC': (64, 'ODBC client'), 'PLUGIN_AUTH': (524288, 'Client supports plugin authentication'), 'PLUGIN_AUTH_LENENC_CLIENT_DATA': (2097152, 'Enable authentication response packet to be larger than 255 bytes'), 'PROTOCOL_41': (512, 'New 4.1 protocol'), 'PS_MULTI_RESULTS': (262144, 'Multi-results in PS-protocol'), 'REMEMBER_OPTIONS': (2147483648, ''), 'RESERVED': (16384, 'Old flag for 4.1 protocol'), 'SECURE_CONNECTION': (32768, 'New 4.1 authentication'), 'SESION_TRACK': (8388608, 'Capable of handling server state change information'), 'SSL': (2048, 'Switch to SSL after handshake'), 'SSL_VERIFY_SERVER_CERT': (1073741824, ''), 'TRANSACTIONS': (8192, 'Client knows about transactions')}¶
-
-
class
mysql.connector.constants.FieldFlag[source]¶ Bases:
mysql.connector.constants._FlagsMySQL Field Flags
Field flags as found in MySQL sources mysql-src/include/mysql_com.h
-
AUTO_INCREMENT= 512¶
-
BINARY= 128¶
-
BINCMP= 131072¶
-
BLOB= 16¶
-
ENUM= 256¶
-
FIELD_IN_ADD_INDEX= 1048576¶
-
FIELD_IN_PART_FUNC= 524288¶
-
FIELD_IS_RENAMED= 2097152¶
-
GET_FIXED_FIELDS= 262144¶
-
GROUP= 16384¶
-
MULTIPLE_KEY= 8¶
-
NOT_NULL= 1¶
-
NO_DEFAULT_VALUE= 4096¶
-
NUM= 16384¶
-
ON_UPDATE_NOW= 8192¶
-
PART_KEY= 32768¶
-
PRI_KEY= 2¶
-
SET= 2048¶
-
TIMESTAMP= 1024¶
-
UNIQUE= 65536¶
-
UNIQUE_KEY= 4¶
-
UNSIGNED= 32¶
-
ZEROFILL= 64¶
-
desc= {'AUTO_INCREMENT': (512, 'field is a autoincrement field'), 'BINARY': (128, 'Field is binary '), 'BINCMP': (131072, 'Intern: Used by sql_yacc'), 'BLOB': (16, 'Field is a blob'), 'ENUM': (256, 'field is an enum'), 'FIELD_IN_ADD_INDEX': (1048576, 'Intern: Field used in ADD INDEX'), 'FIELD_IN_PART_FUNC': (524288, 'Field part of partition func'), 'FIELD_IS_RENAMED': (2097152, 'Intern: Field is being renamed'), 'GET_FIXED_FIELDS': (262144, 'Used to get fields in item tree'), 'GROUP': (16384, 'Intern: Group field'), 'MULTIPLE_KEY': (8, 'Field is part of a key'), 'NOT_NULL': (1, "Field can't be NULL"), 'NO_DEFAULT_VALUE': (4096, "Field doesn't have default value"), 'NUM': (16384, 'Field is num (for clients)'), 'ON_UPDATE_NOW': (8192, 'Field is set to NOW on UPDATE'), 'PART_KEY': (32768, 'Intern; Part of some key'), 'PRI_KEY': (2, 'Field is part of a primary key'), 'SET': (2048, 'field is a set'), 'TIMESTAMP': (1024, 'Field is a timestamp'), 'UNIQUE': (65536, 'Intern: Used by sql_yacc'), 'UNIQUE_KEY': (4, 'Field is part of a unique key'), 'UNSIGNED': (32, 'Field is unsigned'), 'ZEROFILL': (64, 'Field is zerofill')}¶
-
-
class
mysql.connector.constants.FieldType[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL Field Types
-
BIT= 16¶
-
BLOB= 252¶
-
DATE= 10¶
-
DATETIME= 12¶
-
DECIMAL= 0¶
-
DOUBLE= 5¶
-
ENUM= 247¶
-
FLOAT= 4¶
-
GEOMETRY= 255¶
-
INT24= 9¶
-
LONG= 3¶
-
LONGLONG= 8¶
-
LONG_BLOB= 251¶
-
MEDIUM_BLOB= 250¶
-
NEWDATE= 14¶
-
NEWDECIMAL= 246¶
-
NULL= 6¶
-
SET= 248¶
-
SHORT= 2¶
-
STRING= 254¶
-
TIME= 11¶
-
TIMESTAMP= 7¶
-
TINY= 1¶
-
TINY_BLOB= 249¶
-
VARCHAR= 15¶
-
VAR_STRING= 253¶
-
YEAR= 13¶
-
desc= {'BIT': (16, 'BIT'), 'BLOB': (252, 'BLOB'), 'DATE': (10, 'DATE'), 'DATETIME': (12, 'DATETIME'), 'DECIMAL': (0, 'DECIMAL'), 'DOUBLE': (5, 'DOUBLE'), 'ENUM': (247, 'ENUM'), 'FLOAT': (4, 'FLOAT'), 'GEOMETRY': (255, 'GEOMETRY'), 'INT24': (9, 'INT24'), 'LONG': (3, 'LONG'), 'LONGLONG': (8, 'LONGLONG'), 'LONG_BLOB': (251, 'LONG_BLOB'), 'MEDIUM_BLOB': (250, 'MEDIUM_BLOB'), 'NEWDATE': (14, 'NEWDATE'), 'NEWDECIMAL': (246, 'NEWDECIMAL'), 'NULL': (6, 'NULL'), 'SET': (248, 'SET'), 'SHORT': (2, 'SHORT'), 'STRING': (254, 'STRING'), 'TIME': (11, 'TIME'), 'TIMESTAMP': (7, 'TIMESTAMP'), 'TINY': (1, 'TINY'), 'TINY_BLOB': (249, 'TINY_BLOB'), 'VARCHAR': (15, 'VARCHAR'), 'VAR_STRING': (253, 'VAR_STRING'), 'YEAR': (13, 'YEAR')}¶
-
prefix= 'FIELD_TYPE_'¶
-
-
class
mysql.connector.constants.RefreshOption[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL Refresh command options
Options used when sending the COM_REFRESH server command.
-
GRANT= 1¶
-
HOST= 8¶
-
LOG= 2¶
-
SLAVE= 64¶
-
STATUS= 16¶
-
TABLES= 4¶
-
THREADS= 32¶
-
desc= {'GRANT': (1, 'Refresh grant tables'), 'HOSTS': (8, 'Flush host cache'), 'LOG': (2, 'Start on new log file'), 'SLAVE': (64, 'Reset master info and restart slave thread'), 'STATUS': (16, 'Flush status variables'), 'TABLES': (4, 'close all tables'), 'THREADS': (32, 'Flush thread cache')}¶
-
-
class
mysql.connector.constants.SQLMode[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL SQL Modes
The numeric values of SQL Modes are not interesting, only the names are used when setting the SQL_MODE system variable using the MySQL SET command.
See http://dev.mysql.com/doc/refman/5.6/en/server-sql-mode.html
-
ANSI= 'ANSI'¶
-
ANSI_QUOTES= 'ANSI_QUOTES'¶
-
DB2= 'DB2'¶
-
ERROR_FOR_DIVISION_BY_ZERO= 'ERROR_FOR_DIVISION_BY_ZERO'¶
-
HIGH_NOT_PRECEDENCE= 'HIGH_NOT_PRECEDENCE'¶
-
IGNORE_SPACE= 'IGNORE_SPACE'¶
-
INVALID_DATES= 'INVALID_DATES'¶
-
MAXDB= 'MAXDB'¶
-
MSSQL= 'MSSQL'¶
-
MYSQL323= 'MYSQL323'¶
-
MYSQL40= 'MYSQL40'¶
-
NOT_USED= 'NOT_USED'¶
-
NO_AUTO_CREATE_USER= 'NO_AUTO_CREATE_USER'¶
-
NO_AUTO_VALUE_ON_ZERO= 'NO_AUTO_VALUE_ON_ZERO'¶
-
NO_BACKSLASH_ESCAPES= 'NO_BACKSLASH_ESCAPES'¶
-
NO_DIR_IN_CREATE= 'NO_DIR_IN_CREATE'¶
-
NO_ENGINE_SUBSTITUTION= 'NO_ENGINE_SUBSTITUTION'¶
-
NO_FIELD_OPTIONS= 'NO_FIELD_OPTIONS'¶
-
NO_KEY_OPTIONS= 'NO_KEY_OPTIONS'¶
-
NO_TABLE_OPTIONS= 'NO_TABLE_OPTIONS'¶
-
NO_UNSIGNED_SUBTRACTION= 'NO_UNSIGNED_SUBTRACTION'¶
-
NO_ZERO_DATE= 'NO_ZERO_DATE'¶
-
NO_ZERO_IN_DATE= 'NO_ZERO_IN_DATE'¶
-
ONLY_FULL_GROUP_BY= 'ONLY_FULL_GROUP_BY'¶
-
ORACLE= 'ORACLE'¶
-
PAD_CHAR_TO_FULL_LENGTH= 'PAD_CHAR_TO_FULL_LENGTH'¶
-
PIPES_AS_CONCAT= 'PIPES_AS_CONCAT'¶
-
POSTGRESQL= 'POSTGRESQL'¶
-
REAL_AS_FLOAT= 'REAL_AS_FLOAT'¶
-
STRICT_ALL_TABLES= 'STRICT_ALL_TABLES'¶
-
STRICT_TRANS_TABLES= 'STRICT_TRANS_TABLES'¶
-
TRADITIONAL= 'TRADITIONAL'¶
-
-
class
mysql.connector.constants.ServerCmd[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL Server Commands
-
BINLOG_DUMP= 18¶
-
BINLOG_DUMP_GTID= 30¶
-
CHANGE_USER= 17¶
-
CONNECT= 11¶
-
CONNECT_OUT= 20¶
-
CREATE_DB= 5¶
-
DAEMON= 29¶
-
DEBUG= 13¶
-
DELAYED_INSERT= 16¶
-
DROP_DB= 6¶
-
FIELD_LIST= 4¶
-
INIT_DB= 2¶
-
PING= 14¶
-
PROCESS_INFO= 10¶
-
PROCESS_KILL= 12¶
-
QUERY= 3¶
-
QUIT= 1¶
-
REFRESH= 7¶
-
REGISTER_SLAVE= 21¶
-
RESET_CONNECTION= 31¶
-
SET_OPTION= 27¶
-
SHUTDOWN= 8¶
-
SLEEP= 0¶
-
STATISTICS= 9¶
-
STMT_CLOSE= 25¶
-
STMT_EXECUTE= 23¶
-
STMT_FETCH= 28¶
-
STMT_PREPARE= 22¶
-
STMT_RESET= 26¶
-
STMT_SEND_LONG_DATA= 24¶
-
TABLE_DUMP= 19¶
-
TIME= 15¶
-
desc= {'BINLOG_DUMP': (18, 'BINLOG_DUMP'), 'BINLOG_DUMP_GTID': (30, 'BINLOG_DUMP_GTID'), 'CHANGE_USER': (17, 'CHANGE_USER'), 'CONNECT': (11, 'CONNECT'), 'CONNECT_OUT': (20, 'CONNECT_OUT'), 'CREATE_DB': (5, 'CREATE_DB'), 'DAEMON': (29, 'DAEMON'), 'DEBUG': (13, 'DEBUG'), 'DELAYED_INSERT': (16, 'DELAYED_INSERT'), 'DROP_DB': (6, 'DROP_DB'), 'FIELD_LIST': (4, 'FIELD_LIST'), 'INIT_DB': (2, 'INIT_DB'), 'PING': (14, 'PING'), 'PROCESS_INFO': (10, 'PROCESS_INFO'), 'PROCESS_KILL': (12, 'PROCESS_KILL'), 'QUERY': (3, 'QUERY'), 'QUIT': (1, 'QUIT'), 'REFRESH': (7, 'REFRESH'), 'REGISTER_SLAVE': (21, 'REGISTER_SLAVE'), 'RESET_CONNECTION': (31, 'RESET_CONNECTION'), 'SET_OPTION': (27, 'SET_OPTION'), 'SHUTDOWN': (8, 'SHUTDOWN'), 'SLEEP': (0, 'SLEEP'), 'STATISTICS': (9, 'STATISTICS'), 'STMT_CLOSE': (25, 'STMT_CLOSE'), 'STMT_EXECUTE': (23, 'STMT_EXECUTE'), 'STMT_FETCH': (28, 'STMT_FETCH'), 'STMT_PREPARE': (22, 'STMT_PREPARE'), 'STMT_RESET': (26, 'STMT_RESET'), 'STMT_SEND_LONG_DATA': (24, 'STMT_SEND_LONG_DATA'), 'TABLE_DUMP': (19, 'TABLE_DUMP'), 'TIME': (15, 'TIME')}¶
-
-
class
mysql.connector.constants.ServerFlag[source]¶ Bases:
mysql.connector.constants._FlagsMySQL Server Flags
Server flags as found in the MySQL sources mysql-src/include/mysql_com.h
-
MORE_RESULTS_EXISTS= 8¶
-
QUERY_NO_GOOD_INDEX_USED= 16¶
-
QUERY_NO_INDEX_USED= 32¶
-
STATUS_AUTOCOMMIT= 2¶
-
STATUS_CURSOR_EXISTS= 64¶
-
STATUS_DB_DROPPED= 256¶
-
STATUS_IN_TRANS= 1¶
-
STATUS_LAST_ROW_SENT= 128¶
-
STATUS_NO_BACKSLASH_ESCAPES= 512¶
-
desc= {'SERVER_MORE_RESULTS_EXISTS': (8, 'Multi query - next query exists'), 'SERVER_QUERY_NO_GOOD_INDEX_USED': (16, ''), 'SERVER_QUERY_NO_INDEX_USED': (32, ''), 'SERVER_STATUS_AUTOCOMMIT': (2, 'Server in auto_commit mode'), 'SERVER_STATUS_CURSOR_EXISTS': (64, ''), 'SERVER_STATUS_DB_DROPPED': (256, 'A database was dropped'), 'SERVER_STATUS_IN_TRANS': (1, 'Transaction has started'), 'SERVER_STATUS_LAST_ROW_SENT': (128, ''), 'SERVER_STATUS_NO_BACKSLASH_ESCAPES': (512, '')}¶
-
-
class
mysql.connector.constants.ShutdownType[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL Shutdown types
Shutdown types used by the COM_SHUTDOWN server command.
-
KILL_CONNECTION= 255¶
-
KILL_QUERY= 254¶
-
SHUTDOWN_DEFAULT= 0¶
-
SHUTDOWN_WAIT_ALL_BUFFERS= 16¶
-
SHUTDOWN_WAIT_CONNECTIONS= 1¶
-
SHUTDOWN_WAIT_CRITICAL_BUFFERS= 17¶
-
SHUTDOWN_WAIT_TRANSACTIONS= 2¶
-
SHUTDOWN_WAIT_UPDATES= 8¶
-
desc= {'KILL_CONNECTION': (255, '(no description)'), 'KILL_QUERY': (254, '(no description)'), 'SHUTDOWN_DEFAULT': (0, 'defaults to SHUTDOWN_WAIT_ALL_BUFFERS'), 'SHUTDOWN_WAIT_ALL_BUFFERS': (16, 'flush InnoDB and other storage engine buffers'), 'SHUTDOWN_WAIT_CONNECTIONS': (1, 'wait for existing connections to finish'), 'SHUTDOWN_WAIT_CRITICAL_BUFFERS': (17, "don't flush InnoDB buffers, flush other storage engines' buffers"), 'SHUTDOWN_WAIT_TRANSACTIONS': (2, 'wait for existing trans to finish'), 'SHUTDOWN_WAIT_UPDATES': (8, 'wait for existing updates to finish')}¶
-
mysql.connector.conversion module¶
Converting MySQL and Python types
-
class
mysql.connector.conversion.MySQLConverter(charset=None, use_unicode=True)[source]¶ Bases:
mysql.connector.conversion.MySQLConverterBaseDefault conversion class for MySQL Connector/Python.
o escape method: for escaping values send to MySQL o quoting method: for quoting values send to MySQL in statements o conversion mapping: maps Python and MySQL data types to
function for converting them.Whenever one needs to convert values differently, a converter_class argument can be given while instantiating a new connection like cnx.connect(converter_class=CustomMySQLConverterClass).
-
escape(value)[source]¶ Escapes special characters as they are expected to by when MySQL receives them. As found in MySQL source mysys/charset.c
Returns the value if not a string, or the escaped string.
-
quote(buf)[source]¶ - Quote the parameters for commands. General rules:
- o numbers are returns as bytes using ascii codec o None is returned as bytearray(b’NULL’) o Everything else is single quoted ‘<buf>’
Returns a bytearray object.
-
mysql.connector.cursor module¶
Cursor classes
-
class
mysql.connector.cursor.CursorBase[source]¶ Bases:
mysql.connector.abstracts.MySQLCursorAbstractBase for defining MySQLCursor. This class is a skeleton and defines methods and members as required for the Python Database API Specification v2.0.
It’s better to inherite from MySQLCursor.
-
callproc(procname, args=())[source]¶ Calls a stored procedue with the given arguments
The arguments will be set during this session, meaning they will be called like _<procname>__arg<nr> where <nr> is an enumeration (+1) of the arguments.
- Coding Example:
1) Definining the Stored Routine in MySQL: CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT) BEGIN
SET pProd := pFac1 * pFac2;END
2) Executing in Python: args = (5,5,0) # 0 is to hold pprod cursor.callproc(‘multiply’, args) print(cursor.fetchone())
Does not return a value, but a result set will be available when the CALL-statement execute successfully. Raises exceptions when something is wrong.
-
description¶ Returns description of columns in a result
This property returns a list of tuples describing the columns in in a result set. A tuple is described as follows:
(column_name, type, None, None, None, None, null_ok, column_flags) # Addition to PEP-249 specs
Returns a list of tuples.
-
execute(operation, params=(), multi=False)[source]¶ Executes the given operation
Executes the given operation substituting any markers with the given parameters.
- For example, getting all rows where id is 5:
- cursor.execute(“SELECT * FROM t1 WHERE id = %s”, (5,))
The multi argument should be set to True when executing multiple statements in one operation. If not set and multiple results are found, an InterfaceError will be raised.
If warnings where generated, and connection.get_warnings is True, then self._warnings will be a list containing these warnings.
Returns an iterator when multi is True, otherwise None.
-
executemany(operation, seqparams)[source]¶ Execute the given operation multiple times
The executemany() method will execute the operation iterating over the list of parameters in seq_params.
Example: Inserting 3 new employees and their phone number
- data = [
- (‘Jane’,‘555-001’), (‘Joe’, ‘555-001’), (‘John’, ‘555-003’) ]
stmt = “INSERT INTO employees (name, phone) VALUES (‘%s’,’%s’)” cursor.executemany(stmt, data)
INSERT statements are optimized by batching the data, that is using the MySQL multiple rows syntax.
Results are discarded. If they are needed, consider looping over data using the execute() method.
-
fetchmany(size=1)[source]¶ Returns the next set of rows of a query result, returning a list of tuples. When no more rows are available, it returns an empty list.
The number of rows returned can be specified using the size argument, which defaults to one
-
lastrowid¶ Returns the value generated for an AUTO_INCREMENT column
Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement or None when there is no such value available.
Returns a long value or None.
-
rowcount¶ Returns the number of rows produced or affected
This property returns the number of rows produced by queries such as a SELECT, or affected rows when executing DML statements like INSERT or UPDATE.
Note that for non-buffered cursors it is impossible to know the number of rows produced before having fetched them all. For those, the number of rows will be -1 right after execution, and incremented when fetching rows.
Returns an integer.
-
-
class
mysql.connector.cursor.MySQLCursor(connection=None)[source]¶ Bases:
mysql.connector.cursor.CursorBaseDefault cursor for interacting with MySQL
This cursor will execute statements and handle the result. It will not automatically fetch all rows.
MySQLCursor should be inherited whenever other functionallity is required. An example would to change the fetch* member functions to return dictionaries instead of lists of values.
Implements the Python Database API Specification v2.0 (PEP-249)
-
callproc(procname, args=())[source]¶ Calls a stored procedure with the given arguments
The arguments will be set during this session, meaning they will be called like _<procname>__arg<nr> where <nr> is an enumeration (+1) of the arguments.
- Coding Example:
1) Defining the Stored Routine in MySQL: CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT) BEGIN
SET pProd := pFac1 * pFac2;END
2) Executing in Python: args = (5, 5, 0) # 0 is to hold pprod cursor.callproc(‘multiply’, args) print(cursor.fetchone())
For OUT and INOUT parameters the user should provide the type of the parameter as well. The argument should be a tuple with first item as the value of the parameter to pass and second argument the type of the argument.
- In the above example, one can call callproc method like:
- args = (5, 5, (0, ‘INT’)) cursor.callproc(‘multiply’, args)
The type of the argument given in the tuple will be used by the MySQL CAST function to convert the values in the corresponding MySQL type (See CAST in MySQL Reference for more information)
Does not return a value, but a result set will be available when the CALL-statement execute successfully. Raises exceptions when something is wrong.
-
column_names¶ Returns column names
This property returns the columns names as a tuple.
Returns a tuple.
-
execute(operation, params=None, multi=False)[source]¶ Executes the given operation
Executes the given operation substituting any markers with the given parameters.
- For example, getting all rows where id is 5:
- cursor.execute(“SELECT * FROM t1 WHERE id = %s”, (5,))
The multi argument should be set to True when executing multiple statements in one operation. If not set and multiple results are found, an InterfaceError will be raised.
If warnings where generated, and connection.get_warnings is True, then self._warnings will be a list containing these warnings.
Returns an iterator when multi is True, otherwise None.
-
executemany(operation, seq_params)[source]¶ Execute the given operation multiple times
The executemany() method will execute the operation iterating over the list of parameters in seq_params.
Example: Inserting 3 new employees and their phone number
- data = [
- (‘Jane’,‘555-001’), (‘Joe’, ‘555-001’), (‘John’, ‘555-003’) ]
stmt = “INSERT INTO employees (name, phone) VALUES (‘%s’,’%s)” cursor.executemany(stmt, data)
INSERT statements are optimized by batching the data, that is using the MySQL multiple rows syntax.
Results are discarded. If they are needed, consider looping over data using the execute() method.
-
fetchmany(size=None)[source]¶ Returns the next set of rows of a query result, returning a list of tuples. When no more rows are available, it returns an empty list.
The number of rows returned can be specified using the size argument, which defaults to one
-
getlastrowid()[source]¶ Returns the value generated for an AUTO_INCREMENT column
Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement.
Returns a long value or None.
-
statement¶ Returns the executed statement
This property returns the executed statement. When multiple statements were executed, the current statement in the iterator will be returned.
-
stored_results()[source]¶ Returns an iterator for stored results
This method returns an iterator over results which are stored when callproc() is called. The iterator will provide MySQLCursorBuffered instances.
Returns a iterator.
-
with_rows¶ Returns whether the cursor could have rows returned
This property returns True when column descriptions are available and possibly also rows, which will need to be fetched.
Returns True or False.
-
-
class
mysql.connector.cursor.MySQLCursorBuffered(connection=None)[source]¶ Bases:
mysql.connector.cursor.MySQLCursorCursor which fetches rows within execute()
-
fetchmany(size=None)[source]¶ Returns the next set of rows of a query result, returning a list of tuples. When no more rows are available, it returns an empty list.
The number of rows returned can be specified using the size argument, which defaults to one
-
with_rows¶ Returns whether the cursor could have rows returned
This property returns True when column descriptions are available and possibly also rows, which will need to be fetched.
Returns True or False.
-
-
class
mysql.connector.cursor.MySQLCursorBufferedDict(connection=None)[source]¶ Bases:
mysql.connector.cursor.MySQLCursorDict,mysql.connector.cursor.MySQLCursorBufferedBuffered Cursor fetching rows as dictionaries.
-
class
mysql.connector.cursor.MySQLCursorBufferedNamedTuple(connection=None)[source]¶ Bases:
mysql.connector.cursor.MySQLCursorNamedTuple,mysql.connector.cursor.MySQLCursorBufferedBuffered Cursor fetching rows as named tuple.
-
class
mysql.connector.cursor.MySQLCursorBufferedRaw(connection=None)[source]¶ Bases:
mysql.connector.cursor.MySQLCursorBufferedCursor which skips conversion from MySQL datatypes to Python types when fetching rows and fetches rows within execute().
-
with_rows¶ Returns whether the cursor could have rows returned
This property returns True when column descriptions are available and possibly also rows, which will need to be fetched.
Returns True or False.
-
-
class
mysql.connector.cursor.MySQLCursorDict(connection=None)[source]¶ Bases:
mysql.connector.cursor.MySQLCursorCursor fetching rows as dictionaries.
The fetch methods of this class will return dictionaries instead of tuples. Each row is a dictionary that looks like:
- row = {
- “col1”: value1, “col2”: value2
}
-
class
mysql.connector.cursor.MySQLCursorNamedTuple(connection=None)[source]¶ Bases:
mysql.connector.cursor.MySQLCursorCursor fetching rows as named tuple.
The fetch methods of this class will return namedtuples instead of tuples. Each row is returned as a namedtuple and the values can be accessed as: row.col1, row.col2
-
class
mysql.connector.cursor.MySQLCursorPrepared(connection=None)[source]¶ Bases:
mysql.connector.cursor.MySQLCursorCursor using MySQL Prepared Statements
-
close()[source]¶ Close the cursor
This method will try to deallocate the prepared statement and close the cursor.
-
execute(operation, params=(), multi=False)[source]¶ Prepare and execute a MySQL Prepared Statement
This method will preare the given operation and execute it using the optionally given parameters.
If the cursor instance already had a prepared statement, it is first closed.
-
executemany(operation, seq_params)[source]¶ Prepare and execute a MySQL Prepared Statement many times
This method will prepare the given operation and execute with each tuple found the list seq_params.
If the cursor instance already had a prepared statement, it is first closed.
executemany() simply calls execute().
-
-
class
mysql.connector.cursor.MySQLCursorRaw(connection=None)[source]¶ Bases:
mysql.connector.cursor.MySQLCursorSkips conversion from MySQL datatypes to Python types when fetching rows.
mysql.connector.cursor_cext module¶
mysql.connector.custom_types module¶
Custom Python types used by MySQL Connector/Python
mysql.connector.dbapi module¶
This module implements some constructors and singletons as required by the DB API v2.0 (PEP-249).
mysql.connector.errorcode module¶
mysql.connector.errors module¶
Python exceptions
-
exception
mysql.connector.errors.DataError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors reporting problems with processed data
-
exception
mysql.connector.errors.DatabaseError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.ErrorException for errors related to the database
-
exception
mysql.connector.errors.Error(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
ExceptionException that is base class for all other error exceptions
-
exception
mysql.connector.errors.IntegrityError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors regarding relational integrity
-
exception
mysql.connector.errors.InterfaceError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.ErrorException for errors related to the interface
-
exception
mysql.connector.errors.InternalError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors internal database errors
-
exception
mysql.connector.errors.MySQLFabricError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.ErrorException for errors relating to MySQL Fabric
-
exception
mysql.connector.errors.NotSupportedError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors when an unsupported database feature was used
-
exception
mysql.connector.errors.OperationalError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors related to the database’s operation
-
exception
mysql.connector.errors.PoolError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.ErrorException for errors relating to connection pooling
-
exception
mysql.connector.errors.ProgrammingError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors programming errors
-
mysql.connector.errors.custom_error_exception(error=None, exception=None)[source]¶ Define custom exceptions for MySQL server errors
This function defines custom exceptions for MySQL server errors and returns the current set customizations.
If error is a MySQL Server error number, then you have to pass also the exception class.
The error argument can also be a dictionary in which case the key is the server error number, and value the exception to be raised.
If none of the arguments are given, then custom_error_exception() will simply return the current set customizations.
To reset the customizations, simply supply an empty dictionary.
- Examples:
import mysql.connector from mysql.connector import errorcode
# Server error 1028 should raise a DatabaseError mysql.connector.custom_error_exception(
1028, mysql.connector.DatabaseError)# Or using a dictionary: mysql.connector.custom_error_exception({
1028: mysql.connector.DatabaseError, 1029: mysql.connector.OperationalError, })# Reset mysql.connector.custom_error_exception({})
Returns a dictionary.
-
mysql.connector.errors.get_exception(packet)[source]¶ Returns an exception object based on the MySQL error
Returns an exception object based on the MySQL error in the given packet.
Returns an Error-Object.
-
mysql.connector.errors.get_mysql_exception(errno, msg=None, sqlstate=None)[source]¶ Get the exception matching the MySQL error
This function will return an exception based on the SQLState. The given message will be passed on in the returned exception.
The exception returned can be customized using the mysql.connector.custom_error_exception() function.
Returns an Exception
mysql.connector.network module¶
Module implementing low-level socket communication with MySQL servers.
-
class
mysql.connector.network.BaseMySQLSocket[source]¶ Bases:
objectBase class for MySQL socket communication
This class should not be used directly but overloaded, changing the at least the open_connection()-method. Examples of subclasses are
mysql.connector.network.MySQLTCPSocket mysql.connector.network.MySQLUnixSocket-
next_compressed_packet_number¶ Increments the compressed packet number
-
next_packet_number¶ Increments the packet number
-
recv()¶ Receive packets from the MySQL server
-
send(buf, packet_number=None, compressed_packet_number=None)¶ Send packets to the MySQL server
-
send_compressed(buf, packet_number=None, compressed_packet_number=None)[source]¶ Send compressed packets to the MySQL server
-
-
class
mysql.connector.network.MySQLTCPSocket(host='127.0.0.1', port=3306, force_ipv6=False)[source]¶ Bases:
mysql.connector.network.BaseMySQLSocketMySQL socket class using TCP/IP
Opens a TCP/IP connection to the MySQL Server.
-
class
mysql.connector.network.MySQLUnixSocket(unix_socket='/tmp/mysql.sock')[source]¶ Bases:
mysql.connector.network.BaseMySQLSocketMySQL socket class using UNIX sockets
Opens a connection through the UNIX socket of the MySQL Server.
mysql.connector.optionfiles module¶
Implements parser to parse MySQL option files.
-
class
mysql.connector.optionfiles.MySQLOptionsParser(files=None, keep_dashes=True)[source]¶ Bases:
configparser.ConfigParserThis class implements methods to parse MySQL option files
-
get_groups(*args)[source]¶ Returns options as a dictionary.
Returns options from all the groups specified as arguments, returns the options from all groups if no argument provided. Options are overridden when they are found in the next group.
Returns a dictionary
-
get_groups_as_dict(*args)[source]¶ Returns options as dictionary of dictionaries.
Returns options from all the groups specified as arguments. For each group the option are contained in a dictionary. The order in which the groups are specified is unimportant. Also options are not overridden in between the groups.
Returns an dictionary of dictionaries
-
get_groups_as_dict_with_priority(*args)[source]¶ Returns options as dictionary of dictionaries.
Returns options from all the groups specified as arguments. For each group the option are contained in a dictionary. The order in which the groups are specified is unimportant. Also options are not overridden in between the groups.
The value is a tuple with two elements, first being the actual value and second is the priority of the value which is higher for a value read from a higher priority file.
Returns an dictionary of dictionaries
-
mysql.connector.pooling module¶
Implementing pooling of connections to MySQL servers.
-
class
mysql.connector.pooling.MySQLConnectionPool(pool_size=5, pool_name=None, pool_reset_session=True, **kwargs)[source]¶ Bases:
objectClass defining a pool of MySQL connections
-
add_connection(cnx=None)[source]¶ Add a connection to the pool
This method instantiates a MySQLConnection using the configuration passed when initializing the MySQLConnectionPool instance or using the set_config() method. If cnx is a MySQLConnection instance, it will be added to the queue.
Raises PoolError when no configuration is set, when no more connection can be added (maximum reached) or when the connection can not be instantiated.
-
get_connection()[source]¶ Get a connection from the pool
This method returns an PooledMySQLConnection instance which has a reference to the pool that created it, and the next available MySQL connection.
When the MySQL connection is not connect, a reconnect is attempted.
Raises PoolError on errors.
Returns a PooledMySQLConnection instance.
-
pool_name¶ Return the name of the connection pool
-
pool_size¶ Return number of connections managed by the pool
-
reset_session¶ Return whether to reset session
-
set_config(**kwargs)[source]¶ Set the connection configuration for MySQLConnection instances
This method sets the configuration used for creating MySQLConnection instances. See MySQLConnection for valid connection arguments.
Raises PoolError when a connection argument is not valid, missing or not supported by MySQLConnection.
-
-
class
mysql.connector.pooling.PooledMySQLConnection(pool, cnx)[source]¶ Bases:
objectClass holding a MySQL Connection in a pool
PooledMySQLConnection is used by MySQLConnectionPool to return an instance holding a MySQL connection. It works like a MySQLConnection except for methods like close() and config().
The close()-method will add the connection back to the pool rather than disconnecting from the MySQL server.
Configuring the connection have to be done through the MySQLConnectionPool method set_config(). Using config() on pooled connection will raise a PoolError.
-
close()[source]¶ Do not close, but add connection back to pool
The close() method does not close the connection with the MySQL server. The connection is added back to the pool so it can be reused.
When the pool is configured to reset the session, the session state will be cleared by re-authenticating the user.
-
pool_name¶ Return the name of the connection pool
-
mysql.connector.protocol module¶
Implements the MySQL Client/Server protocol
-
class
mysql.connector.protocol.MySQLProtocol[source]¶ Bases:
objectImplements MySQL client/server protocol
Create and parses MySQL packets.
-
make_auth(handshake, username=None, password=None, database=None, charset=33, client_flags=0, max_allowed_packet=1073741824, ssl_enabled=False, auth_plugin=None)[source]¶ Make a MySQL Authentication packet
-
make_auth_ssl(charset=33, client_flags=0, max_allowed_packet=1073741824)[source]¶ Make a SSL authentication packet
-
make_change_user(handshake, username=None, password=None, database=None, charset=33, client_flags=0, ssl_enabled=False, auth_plugin=None)[source]¶ Make a MySQL packet with the Change User command
-
make_stmt_execute(statement_id, data=(), parameters=(), flags=0, long_data_used=None, charset='utf8')[source]¶ Make a MySQL packet with the Statement Execute command
-
mysql.connector.utils module¶
Utilities
-
mysql.connector.utils.int1store(i)[source]¶ Takes an unsigned byte (1 byte) and packs it as a bytes-object.
Returns string.
-
mysql.connector.utils.int2store(i)[source]¶ Takes an unsigned short (2 bytes) and packs it as a bytes-object.
Returns string.
-
mysql.connector.utils.int3store(i)[source]¶ Takes an unsigned integer (3 bytes) and packs it as a bytes-object.
Returns string.
-
mysql.connector.utils.int4store(i)[source]¶ Takes an unsigned integer (4 bytes) and packs it as a bytes-object.
Returns string.
-
mysql.connector.utils.int8store(i)[source]¶ Takes an unsigned integer (8 bytes) and packs it as string.
Returns string.
-
mysql.connector.utils.intstore(i)[source]¶ Takes an unsigned integers and packs it as a bytes-object.
This function uses int1store, int2store, int3store, int4store or int8store depending on the integer value.
returns string.
-
mysql.connector.utils.lc_int(i)[source]¶ Takes an unsigned integer and packs it as bytes, with the information of how much bytes the encoded int takes.
-
mysql.connector.utils.print_buffer(abuffer, prefix=None, limit=30)[source]¶ Debug function printing output of _digest_buffer()
-
mysql.connector.utils.read_bytes(buf, size)[source]¶ Reads bytes from a buffer.
Returns a tuple with buffer less the read bytes, and the bytes.
-
mysql.connector.utils.read_int(buf, size)[source]¶ Read an integer from buffer
Returns a tuple (truncated buffer, int)
-
mysql.connector.utils.read_lc_int(buf)[source]¶ Takes a buffer and reads an length code string from the start.
Returns a tuple with buffer less the integer and the integer read.
-
mysql.connector.utils.read_lc_string(buf)[source]¶ Takes a buffer and reads a length coded string from the start.
This is how Length coded strings work
If the string is 250 bytes long or smaller, then it looks like this:
<– 1b –> +———-+————————- | length | a string goes here +———-+————————-If the string is bigger than 250, then it looks like this:
<- 1b -><- 2/3/8 -> +——+———–+————————- | type | length | a string goes here +——+———–+————————-
- if type == ü:
- length is code in next 2 bytes
- elif type == ý:
- length is code in next 3 bytes
- elif type == þ:
- length is code in next 8 bytes
NULL has a special value. If the buffer starts with û then it’s a NULL and we return None as value.
Returns a tuple (trucated buffer, bytes).
mysql.connector.version module¶
MySQL Connector/Python version information
The file version.py gets installed and is available after installation as mysql.connector.version.
Module contents¶
MySQL Connector/Python - MySQL driver written in Python
-
class
mysql.connector.MySQLConnection(*args, **kwargs)[source]¶ Bases:
mysql.connector.abstracts.MySQLConnectionAbstractConnection to a MySQL Server
-
cmd_change_user(username='', password='', database='', charset=33)[source]¶ Change the current logged in user
This method allows to change the current logged in user information. The result is a dictionary with OK packet information.
Returns a dict()
-
cmd_debug()[source]¶ Send the DEBUG command
This method sends the DEBUG command to the MySQL server, which requires the MySQL user to have SUPER privilege. The output will go to the MySQL server error log and the result of this method is a dictionary with EOF packet information.
Returns a dict()
-
cmd_init_db(database)[source]¶ Change the current database
This method changes the current (default) database by sending the INIT_DB command. The result is a dictionary containing the OK packet information.
Returns a dict()
-
cmd_ping()[source]¶ Send the PING command
This method sends the PING command to the MySQL server. It is used to check if the the connection is still valid. The result of this method is dictionary with OK packet information.
Returns a dict()
-
cmd_process_kill(mysql_pid)[source]¶ Kill a MySQL process
This method send the PROCESS_KILL command to the server along with the process ID. The result is a dictionary with the OK packet information.
Returns a dict()
-
cmd_query(query, raw=False, buffered=False, raw_as_string=False)[source]¶ Send a query to the MySQL server
This method send the query to the MySQL server and returns the result.
If there was a text result, a tuple will be returned consisting of the number of columns and a list containing information about these columns.
When the query doesn’t return a text result, the OK or EOF packet information as dictionary will be returned. In case the result was an error, exception errors.Error will be raised.
Returns a tuple()
-
cmd_query_iter(statements)[source]¶ Send one or more statements to the MySQL server
Similar to the cmd_query method, but instead returns a generator object to iterate through results. It sends the statements to the MySQL server and through the iterator you can get the results.
statement = ‘SELECT 1; INSERT INTO t1 VALUES (); SELECT 2’ for result in cnx.cmd_query(statement, iterate=True):
- if ‘columns’ in result:
- columns = result[‘columns’] rows = cnx.get_rows()
- else:
- # do something useful with INSERT result
Returns a generator.
-
cmd_quit()[source]¶ Close the current connection with the server
This method sends the QUIT command to the MySQL server, closing the current connection. Since the no response can be returned to the client, cmd_quit() will return the packet it send.
Returns a str()
-
cmd_refresh(options)[source]¶ Send the Refresh command to the MySQL server
This method sends the Refresh command to the MySQL server. The options argument should be a bitwise value using constants.RefreshOption. Usage example:
RefreshOption = mysql.connector.RefreshOption refresh = RefreshOption.LOG | RefreshOption.THREADS cnx.cmd_refresh(refresh)The result is a dictionary with the OK packet information.
Returns a dict()
-
cmd_reset_connection()[source]¶ Resets the session state without re-authenticating
Works only for MySQL server 5.7.3 or later. The result is a dictionary with OK packet information.
Returns a dict()
-
cmd_shutdown(shutdown_type=None)[source]¶ Shut down the MySQL Server
This method sends the SHUTDOWN command to the MySQL server and is only possible if the current user has SUPER privileges. The result is a dictionary containing the OK packet information.
Note: Most applications and scripts do not the SUPER privilege.
Returns a dict()
-
cmd_statistics()[source]¶ Send the statistics command to the MySQL Server
This method sends the STATISTICS command to the MySQL server. The result is a dictionary with various statistical information.
Returns a dict()
-
cmd_stmt_close(statement_id)[source]¶ Deallocate a prepared MySQL statement
This method deallocates the prepared statement using the statement_id. Note that the MySQL server does not return anything.
-
cmd_stmt_execute(statement_id, data=(), parameters=(), flags=0)[source]¶ Execute a prepared MySQL statement
-
cmd_stmt_prepare(statement)[source]¶ Prepare a MySQL statement
This method will send the PREPARE command to MySQL together with the given statement.
Returns a dict()
-
cmd_stmt_reset(statement_id)[source]¶ Reset data for prepared statement sent as long data
The result is a dictionary with OK packet information.
Returns a dict()
-
cmd_stmt_send_long_data(statement_id, param_id, data)[source]¶ Send data for a column
This methods send data for a column (for example BLOB) for statement identified by statement_id. The param_id indicate which parameter the data belongs too. The data argument should be a file-like object.
Since MySQL does not send anything back, no error is raised. When the MySQL server is not reachable, an OperationalError is raised.
cmd_stmt_send_long_data should be called before cmd_stmt_execute.
The total bytes send is returned.
Returns int.
-
connection_id¶ MySQL connection ID
-
cursor(buffered=None, raw=None, prepared=None, cursor_class=None, dictionary=None, named_tuple=None)[source]¶ Instantiates and returns a cursor
By default, MySQLCursor is returned. Depending on the options while connecting, a buffered and/or raw cursor is instantiated instead. Also depending upon the cursor options, rows can be returned as dictionary or named tuple.
Dictionary and namedtuple based cursors are available with buffered output but not raw.
It is possible to also give a custom cursor through the cursor_class parameter, but it needs to be a subclass of mysql.connector.cursor.CursorBase.
Raises ProgrammingError when cursor_class is not a subclass of CursorBase. Raises ValueError when cursor is not available.
Returns a cursor-object
-
database¶ Get the current database
-
disconnect()¶ Disconnect from the MySQL server
-
get_row(binary=False, columns=None)[source]¶ Get the next rows returned by the MySQL server
This method gets one row from the result set after sending, for example, the query command. The result is a tuple consisting of the row and the EOF packet. If no row was available in the result set, the row data will be None.
Returns a tuple.
-
get_rows(count=None, binary=False, columns=None)[source]¶ Get all rows returned by the MySQL server
This method gets all rows returned by the MySQL server after sending, for example, the query command. The result is a tuple consisting of a list of rows and the EOF packet.
Returns a tuple()
-
in_transaction¶ MySQL session has started a transaction
-
is_connected()[source]¶ Reports whether the connection to MySQL Server is available
This method checks whether the connection to MySQL is available. It is similar to ping(), but unlike the ping()-method, either True or False is returned and no exception is raised.
Returns True or False.
-
ping(reconnect=False, attempts=1, delay=0)[source]¶ Check availability of the MySQL server
When reconnect is set to True, one or more attempts are made to try to reconnect to the MySQL server using the reconnect()-method.
delay is the number of seconds to wait between each retry.
When the connection is not available, an InterfaceError is raised. Use the is_connected()-method if you just want to check the connection without raising an error.
Raises InterfaceError on errors.
-
reconnect(attempts=1, delay=0)[source]¶ Attempt to reconnect to the MySQL server
The argument attempts should be the number of times a reconnect is tried. The delay argument is the number of seconds to wait between each retry.
You may want to set the number of attempts higher and use delay when you expect the MySQL server to be down for maintenance or when you expect the network to be temporary unavailable.
Raises InterfaceError on errors.
-
reset_session(user_variables=None, session_variables=None)[source]¶ Clears the current active session
This method resets the session state, if the MySQL server is 5.7.3 or later active session will be reset without re-authenticating. For other server versions session will be reset by re-authenticating.
It is possible to provide a sequence of variables and their values to be set after clearing the session. This is possible for both user defined variables and session variables. This method takes two arguments user_variables and session_variables which are dictionaries.
Raises OperationalError if not connected, InternalError if there are unread results and InterfaceError on errors.
-
-
mysql.connector.Connect(*args, **kwargs)¶ Create or get a MySQL connection object
In its simpliest form, Connect() will open a connection to a MySQL server and return a MySQLConnection object.
When any connection pooling arguments are given, for example pool_name or pool_size, a pool is created or a previously one is used to return a PooledMySQLConnection.
Returns MySQLConnection or PooledMySQLConnection.
-
mysql.connector.custom_error_exception(error=None, exception=None)[source]¶ Define custom exceptions for MySQL server errors
This function defines custom exceptions for MySQL server errors and returns the current set customizations.
If error is a MySQL Server error number, then you have to pass also the exception class.
The error argument can also be a dictionary in which case the key is the server error number, and value the exception to be raised.
If none of the arguments are given, then custom_error_exception() will simply return the current set customizations.
To reset the customizations, simply supply an empty dictionary.
- Examples:
import mysql.connector from mysql.connector import errorcode
# Server error 1028 should raise a DatabaseError mysql.connector.custom_error_exception(
1028, mysql.connector.DatabaseError)# Or using a dictionary: mysql.connector.custom_error_exception({
1028: mysql.connector.DatabaseError, 1029: mysql.connector.OperationalError, })# Reset mysql.connector.custom_error_exception({})
Returns a dictionary.
-
class
mysql.connector.FieldType[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL Field Types
-
BIT= 16¶
-
BLOB= 252¶
-
DATE= 10¶
-
DATETIME= 12¶
-
DECIMAL= 0¶
-
DOUBLE= 5¶
-
ENUM= 247¶
-
FLOAT= 4¶
-
GEOMETRY= 255¶
-
INT24= 9¶
-
LONG= 3¶
-
LONGLONG= 8¶
-
LONG_BLOB= 251¶
-
MEDIUM_BLOB= 250¶
-
NEWDATE= 14¶
-
NEWDECIMAL= 246¶
-
NULL= 6¶
-
SET= 248¶
-
SHORT= 2¶
-
STRING= 254¶
-
TIME= 11¶
-
TIMESTAMP= 7¶
-
TINY= 1¶
-
TINY_BLOB= 249¶
-
VARCHAR= 15¶
-
VAR_STRING= 253¶
-
YEAR= 13¶
-
desc= {'BIT': (16, 'BIT'), 'BLOB': (252, 'BLOB'), 'DATE': (10, 'DATE'), 'DATETIME': (12, 'DATETIME'), 'DECIMAL': (0, 'DECIMAL'), 'DOUBLE': (5, 'DOUBLE'), 'ENUM': (247, 'ENUM'), 'FLOAT': (4, 'FLOAT'), 'GEOMETRY': (255, 'GEOMETRY'), 'INT24': (9, 'INT24'), 'LONG': (3, 'LONG'), 'LONGLONG': (8, 'LONGLONG'), 'LONG_BLOB': (251, 'LONG_BLOB'), 'MEDIUM_BLOB': (250, 'MEDIUM_BLOB'), 'NEWDATE': (14, 'NEWDATE'), 'NEWDECIMAL': (246, 'NEWDECIMAL'), 'NULL': (6, 'NULL'), 'SET': (248, 'SET'), 'SHORT': (2, 'SHORT'), 'STRING': (254, 'STRING'), 'TIME': (11, 'TIME'), 'TIMESTAMP': (7, 'TIMESTAMP'), 'TINY': (1, 'TINY'), 'TINY_BLOB': (249, 'TINY_BLOB'), 'VARCHAR': (15, 'VARCHAR'), 'VAR_STRING': (253, 'VAR_STRING'), 'YEAR': (13, 'YEAR')}¶
-
prefix= 'FIELD_TYPE_'¶
-
-
class
mysql.connector.FieldFlag[source]¶ Bases:
mysql.connector.constants._FlagsMySQL Field Flags
Field flags as found in MySQL sources mysql-src/include/mysql_com.h
-
AUTO_INCREMENT= 512¶
-
BINARY= 128¶
-
BINCMP= 131072¶
-
BLOB= 16¶
-
ENUM= 256¶
-
FIELD_IN_ADD_INDEX= 1048576¶
-
FIELD_IN_PART_FUNC= 524288¶
-
FIELD_IS_RENAMED= 2097152¶
-
GET_FIXED_FIELDS= 262144¶
-
GROUP= 16384¶
-
MULTIPLE_KEY= 8¶
-
NOT_NULL= 1¶
-
NO_DEFAULT_VALUE= 4096¶
-
NUM= 16384¶
-
ON_UPDATE_NOW= 8192¶
-
PART_KEY= 32768¶
-
PRI_KEY= 2¶
-
SET= 2048¶
-
TIMESTAMP= 1024¶
-
UNIQUE= 65536¶
-
UNIQUE_KEY= 4¶
-
UNSIGNED= 32¶
-
ZEROFILL= 64¶
-
desc= {'AUTO_INCREMENT': (512, 'field is a autoincrement field'), 'BINARY': (128, 'Field is binary '), 'BINCMP': (131072, 'Intern: Used by sql_yacc'), 'BLOB': (16, 'Field is a blob'), 'ENUM': (256, 'field is an enum'), 'FIELD_IN_ADD_INDEX': (1048576, 'Intern: Field used in ADD INDEX'), 'FIELD_IN_PART_FUNC': (524288, 'Field part of partition func'), 'FIELD_IS_RENAMED': (2097152, 'Intern: Field is being renamed'), 'GET_FIXED_FIELDS': (262144, 'Used to get fields in item tree'), 'GROUP': (16384, 'Intern: Group field'), 'MULTIPLE_KEY': (8, 'Field is part of a key'), 'NOT_NULL': (1, "Field can't be NULL"), 'NO_DEFAULT_VALUE': (4096, "Field doesn't have default value"), 'NUM': (16384, 'Field is num (for clients)'), 'ON_UPDATE_NOW': (8192, 'Field is set to NOW on UPDATE'), 'PART_KEY': (32768, 'Intern; Part of some key'), 'PRI_KEY': (2, 'Field is part of a primary key'), 'SET': (2048, 'field is a set'), 'TIMESTAMP': (1024, 'Field is a timestamp'), 'UNIQUE': (65536, 'Intern: Used by sql_yacc'), 'UNIQUE_KEY': (4, 'Field is part of a unique key'), 'UNSIGNED': (32, 'Field is unsigned'), 'ZEROFILL': (64, 'Field is zerofill')}¶
-
-
class
mysql.connector.ClientFlag[source]¶ Bases:
mysql.connector.constants._FlagsMySQL Client Flags
Client options as found in the MySQL sources mysql-src/include/mysql_com.h
-
CAN_HANDLE_EXPIRED_PASSWORDS= 4194304¶
-
COMPRESS= 32¶
-
CONNECT_ARGS= 1048576¶
-
CONNECT_WITH_DB= 8¶
-
DEPRECATE_EOF= 16777216¶
-
FOUND_ROWS= 2¶
-
IGNORE_SIGPIPE= 4096¶
-
IGNORE_SPACE= 256¶
-
INTERACTIVE= 1024¶
-
LOCAL_FILES= 128¶
-
LONG_FLAG= 4¶
-
LONG_PASSWD= 1¶
-
MULTI_RESULTS= 131072¶
-
MULTI_STATEMENTS= 65536¶
-
NO_SCHEMA= 16¶
-
ODBC= 64¶
-
PLUGIN_AUTH= 524288¶
-
PLUGIN_AUTH_LENENC_CLIENT_DATA= 2097152¶
-
PROTOCOL_41= 512¶
-
PS_MULTI_RESULTS= 262144¶
-
REMEMBER_OPTIONS= 2147483648¶
-
RESERVED= 16384¶
-
SECURE_CONNECTION= 32768¶
-
SESION_TRACK= 8388608¶
-
SSL= 2048¶
-
SSL_VERIFY_SERVER_CERT= 1073741824¶
-
TRANSACTIONS= 8192¶
-
default= [1, 4, 8, 512, 8192, 32768, 65536, 131072, 128]¶
-
desc= {'CAN_HANDLE_EXPIRED_PASSWORDS': (4194304, "Don't close the connection for a connection with expired password"), 'COMPRESS': (32, 'Can use compression protocol'), 'CONNECT_ARGS': (1048576, 'Client supports connection attributes'), 'CONNECT_WITH_DB': (8, 'One can specify db on connect'), 'DEPRECATE_EOF': (16777216, 'Client no longer needs EOF packet'), 'FOUND_ROWS': (2, 'Found instead of affected rows'), 'IGNORE_SIGPIPE': (4096, 'IGNORE sigpipes'), 'IGNORE_SPACE': (256, "Ignore spaces before ''"), 'INTERACTIVE': (1024, 'This is an interactive client'), 'LOCAL_FILES': (128, 'Can use LOAD DATA LOCAL'), 'LONG_FLAG': (4, 'Get all column flags'), 'LONG_PASSWD': (1, 'New more secure passwords'), 'MULTI_RESULTS': (131072, 'Enable/disable multi-results'), 'MULTI_STATEMENTS': (65536, 'Enable/disable multi-stmt support'), 'NO_SCHEMA': (16, "Don't allow database.table.column"), 'ODBC': (64, 'ODBC client'), 'PLUGIN_AUTH': (524288, 'Client supports plugin authentication'), 'PLUGIN_AUTH_LENENC_CLIENT_DATA': (2097152, 'Enable authentication response packet to be larger than 255 bytes'), 'PROTOCOL_41': (512, 'New 4.1 protocol'), 'PS_MULTI_RESULTS': (262144, 'Multi-results in PS-protocol'), 'REMEMBER_OPTIONS': (2147483648, ''), 'RESERVED': (16384, 'Old flag for 4.1 protocol'), 'SECURE_CONNECTION': (32768, 'New 4.1 authentication'), 'SESION_TRACK': (8388608, 'Capable of handling server state change information'), 'SSL': (2048, 'Switch to SSL after handshake'), 'SSL_VERIFY_SERVER_CERT': (1073741824, ''), 'TRANSACTIONS': (8192, 'Client knows about transactions')}¶
-
-
class
mysql.connector.CharacterSet[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL supported character sets and collations
List of character sets with their collations supported by MySQL. This maps to the character set we get from the server within the handshake packet.
The list is hardcode so we avoid a database query when getting the name of the used character set or collation.
-
desc= [None, ('big5', 'big5_chinese_ci', True), ('latin2', 'latin2_czech_cs', False), ('dec8', 'dec8_swedish_ci', True), ('cp850', 'cp850_general_ci', True), ('latin1', 'latin1_german1_ci', False), ('hp8', 'hp8_english_ci', True), ('koi8r', 'koi8r_general_ci', True), ('latin1', 'latin1_swedish_ci', True), ('latin2', 'latin2_general_ci', True), ('swe7', 'swe7_swedish_ci', True), ('ascii', 'ascii_general_ci', True), ('ujis', 'ujis_japanese_ci', True), ('sjis', 'sjis_japanese_ci', True), ('cp1251', 'cp1251_bulgarian_ci', False), ('latin1', 'latin1_danish_ci', False), ('hebrew', 'hebrew_general_ci', True), None, ('tis620', 'tis620_thai_ci', True), ('euckr', 'euckr_korean_ci', True), ('latin7', 'latin7_estonian_cs', False), ('latin2', 'latin2_hungarian_ci', False), ('koi8u', 'koi8u_general_ci', True), ('cp1251', 'cp1251_ukrainian_ci', False), ('gb2312', 'gb2312_chinese_ci', True), ('greek', 'greek_general_ci', True), ('cp1250', 'cp1250_general_ci', True), ('latin2', 'latin2_croatian_ci', False), ('gbk', 'gbk_chinese_ci', True), ('cp1257', 'cp1257_lithuanian_ci', False), ('latin5', 'latin5_turkish_ci', True), ('latin1', 'latin1_german2_ci', False), ('armscii8', 'armscii8_general_ci', True), ('utf8', 'utf8_general_ci', True), ('cp1250', 'cp1250_czech_cs', False), ('ucs2', 'ucs2_general_ci', True), ('cp866', 'cp866_general_ci', True), ('keybcs2', 'keybcs2_general_ci', True), ('macce', 'macce_general_ci', True), ('macroman', 'macroman_general_ci', True), ('cp852', 'cp852_general_ci', True), ('latin7', 'latin7_general_ci', True), ('latin7', 'latin7_general_cs', False), ('macce', 'macce_bin', False), ('cp1250', 'cp1250_croatian_ci', False), ('utf8mb4', 'utf8mb4_general_ci', True), ('utf8mb4', 'utf8mb4_bin', False), ('latin1', 'latin1_bin', False), ('latin1', 'latin1_general_ci', False), ('latin1', 'latin1_general_cs', False), ('cp1251', 'cp1251_bin', False), ('cp1251', 'cp1251_general_ci', True), ('cp1251', 'cp1251_general_cs', False), ('macroman', 'macroman_bin', False), ('utf16', 'utf16_general_ci', True), ('utf16', 'utf16_bin', False), ('utf16le', 'utf16le_general_ci', True), ('cp1256', 'cp1256_general_ci', True), ('cp1257', 'cp1257_bin', False), ('cp1257', 'cp1257_general_ci', True), ('utf32', 'utf32_general_ci', True), ('utf32', 'utf32_bin', False), ('utf16le', 'utf16le_bin', False), ('binary', 'binary', True), ('armscii8', 'armscii8_bin', False), ('ascii', 'ascii_bin', False), ('cp1250', 'cp1250_bin', False), ('cp1256', 'cp1256_bin', False), ('cp866', 'cp866_bin', False), ('dec8', 'dec8_bin', False), ('greek', 'greek_bin', False), ('hebrew', 'hebrew_bin', False), ('hp8', 'hp8_bin', False), ('keybcs2', 'keybcs2_bin', False), ('koi8r', 'koi8r_bin', False), ('koi8u', 'koi8u_bin', False), None, ('latin2', 'latin2_bin', False), ('latin5', 'latin5_bin', False), ('latin7', 'latin7_bin', False), ('cp850', 'cp850_bin', False), ('cp852', 'cp852_bin', False), ('swe7', 'swe7_bin', False), ('utf8', 'utf8_bin', False), ('big5', 'big5_bin', False), ('euckr', 'euckr_bin', False), ('gb2312', 'gb2312_bin', False), ('gbk', 'gbk_bin', False), ('sjis', 'sjis_bin', False), ('tis620', 'tis620_bin', False), ('ucs2', 'ucs2_bin', False), ('ujis', 'ujis_bin', False), ('geostd8', 'geostd8_general_ci', True), ('geostd8', 'geostd8_bin', False), ('latin1', 'latin1_spanish_ci', False), ('cp932', 'cp932_japanese_ci', True), ('cp932', 'cp932_bin', False), ('eucjpms', 'eucjpms_japanese_ci', True), ('eucjpms', 'eucjpms_bin', False), ('cp1250', 'cp1250_polish_ci', False), None, ('utf16', 'utf16_unicode_ci', False), ('utf16', 'utf16_icelandic_ci', False), ('utf16', 'utf16_latvian_ci', False), ('utf16', 'utf16_romanian_ci', False), ('utf16', 'utf16_slovenian_ci', False), ('utf16', 'utf16_polish_ci', False), ('utf16', 'utf16_estonian_ci', False), ('utf16', 'utf16_spanish_ci', False), ('utf16', 'utf16_swedish_ci', False), ('utf16', 'utf16_turkish_ci', False), ('utf16', 'utf16_czech_ci', False), ('utf16', 'utf16_danish_ci', False), ('utf16', 'utf16_lithuanian_ci', False), ('utf16', 'utf16_slovak_ci', False), ('utf16', 'utf16_spanish2_ci', False), ('utf16', 'utf16_roman_ci', False), ('utf16', 'utf16_persian_ci', False), ('utf16', 'utf16_esperanto_ci', False), ('utf16', 'utf16_hungarian_ci', False), ('utf16', 'utf16_sinhala_ci', False), ('utf16', 'utf16_german2_ci', False), ('utf16', 'utf16_croatian_ci', False), ('utf16', 'utf16_unicode_520_ci', False), ('utf16', 'utf16_vietnamese_ci', False), None, None, None, ('ucs2', 'ucs2_unicode_ci', False), ('ucs2', 'ucs2_icelandic_ci', False), ('ucs2', 'ucs2_latvian_ci', False), ('ucs2', 'ucs2_romanian_ci', False), ('ucs2', 'ucs2_slovenian_ci', False), ('ucs2', 'ucs2_polish_ci', False), ('ucs2', 'ucs2_estonian_ci', False), ('ucs2', 'ucs2_spanish_ci', False), ('ucs2', 'ucs2_swedish_ci', False), ('ucs2', 'ucs2_turkish_ci', False), ('ucs2', 'ucs2_czech_ci', False), ('ucs2', 'ucs2_danish_ci', False), ('ucs2', 'ucs2_lithuanian_ci', False), ('ucs2', 'ucs2_slovak_ci', False), ('ucs2', 'ucs2_spanish2_ci', False), ('ucs2', 'ucs2_roman_ci', False), ('ucs2', 'ucs2_persian_ci', False), ('ucs2', 'ucs2_esperanto_ci', False), ('ucs2', 'ucs2_hungarian_ci', False), ('ucs2', 'ucs2_sinhala_ci', False), ('ucs2', 'ucs2_german2_ci', False), ('ucs2', 'ucs2_croatian_ci', False), ('ucs2', 'ucs2_unicode_520_ci', False), ('ucs2', 'ucs2_vietnamese_ci', False), None, None, None, None, None, None, None, ('ucs2', 'ucs2_general_mysql500_ci', False), ('utf32', 'utf32_unicode_ci', False), ('utf32', 'utf32_icelandic_ci', False), ('utf32', 'utf32_latvian_ci', False), ('utf32', 'utf32_romanian_ci', False), ('utf32', 'utf32_slovenian_ci', False), ('utf32', 'utf32_polish_ci', False), ('utf32', 'utf32_estonian_ci', False), ('utf32', 'utf32_spanish_ci', False), ('utf32', 'utf32_swedish_ci', False), ('utf32', 'utf32_turkish_ci', False), ('utf32', 'utf32_czech_ci', False), ('utf32', 'utf32_danish_ci', False), ('utf32', 'utf32_lithuanian_ci', False), ('utf32', 'utf32_slovak_ci', False), ('utf32', 'utf32_spanish2_ci', False), ('utf32', 'utf32_roman_ci', False), ('utf32', 'utf32_persian_ci', False), ('utf32', 'utf32_esperanto_ci', False), ('utf32', 'utf32_hungarian_ci', False), ('utf32', 'utf32_sinhala_ci', False), ('utf32', 'utf32_german2_ci', False), ('utf32', 'utf32_croatian_ci', False), ('utf32', 'utf32_unicode_520_ci', False), ('utf32', 'utf32_vietnamese_ci', False), None, None, None, None, None, None, None, None, ('utf8', 'utf8_unicode_ci', False), ('utf8', 'utf8_icelandic_ci', False), ('utf8', 'utf8_latvian_ci', False), ('utf8', 'utf8_romanian_ci', False), ('utf8', 'utf8_slovenian_ci', False), ('utf8', 'utf8_polish_ci', False), ('utf8', 'utf8_estonian_ci', False), ('utf8', 'utf8_spanish_ci', False), ('utf8', 'utf8_swedish_ci', False), ('utf8', 'utf8_turkish_ci', False), ('utf8', 'utf8_czech_ci', False), ('utf8', 'utf8_danish_ci', False), ('utf8', 'utf8_lithuanian_ci', False), ('utf8', 'utf8_slovak_ci', False), ('utf8', 'utf8_spanish2_ci', False), ('utf8', 'utf8_roman_ci', False), ('utf8', 'utf8_persian_ci', False), ('utf8', 'utf8_esperanto_ci', False), ('utf8', 'utf8_hungarian_ci', False), ('utf8', 'utf8_sinhala_ci', False), ('utf8', 'utf8_german2_ci', False), ('utf8', 'utf8_croatian_ci', False), ('utf8', 'utf8_unicode_520_ci', False), ('utf8', 'utf8_vietnamese_ci', False), None, None, None, None, None, None, None, ('utf8', 'utf8_general_mysql500_ci', False), ('utf8mb4', 'utf8mb4_unicode_ci', False), ('utf8mb4', 'utf8mb4_icelandic_ci', False), ('utf8mb4', 'utf8mb4_latvian_ci', False), ('utf8mb4', 'utf8mb4_romanian_ci', False), ('utf8mb4', 'utf8mb4_slovenian_ci', False), ('utf8mb4', 'utf8mb4_polish_ci', False), ('utf8mb4', 'utf8mb4_estonian_ci', False), ('utf8mb4', 'utf8mb4_spanish_ci', False), ('utf8mb4', 'utf8mb4_swedish_ci', False), ('utf8mb4', 'utf8mb4_turkish_ci', False), ('utf8mb4', 'utf8mb4_czech_ci', False), ('utf8mb4', 'utf8mb4_danish_ci', False), ('utf8mb4', 'utf8mb4_lithuanian_ci', False), ('utf8mb4', 'utf8mb4_slovak_ci', False), ('utf8mb4', 'utf8mb4_spanish2_ci', False), ('utf8mb4', 'utf8mb4_roman_ci', False), ('utf8mb4', 'utf8mb4_persian_ci', False), ('utf8mb4', 'utf8mb4_esperanto_ci', False), ('utf8mb4', 'utf8mb4_hungarian_ci', False), ('utf8mb4', 'utf8mb4_sinhala_ci', False), ('utf8mb4', 'utf8mb4_german2_ci', False), ('utf8mb4', 'utf8mb4_croatian_ci', False), ('utf8mb4', 'utf8mb4_unicode_520_ci', False), ('utf8mb4', 'utf8mb4_vietnamese_ci', False), ('gb18030', 'gb18030_chinese_ci', True), ('gb18030', 'gb18030_bin', False), ('gb18030', 'gb18030_unicode_520_ci', False)]¶
-
classmethod
get_charset_info(charset=None, collation=None)[source]¶ Get character set information using charset name and/or collation
Retrieves character set and collation information given character set name and/or a collation name. If charset is an integer, it will look up the character set based on the MySQL’s ID. For example:
get_charset_info(‘utf8’,None) get_charset_info(collation=’utf8_general_ci’) get_charset_info(47)Raises ProgrammingError when character set is not supported.
Returns a tuple with (id, characterset name, collation)
-
classmethod
get_default_collation(charset)[source]¶ Retrieves the default collation for given character set
Raises ProgrammingError when character set is not supported.
Returns list (collation, charset, index)
-
classmethod
get_desc(setid)[source]¶ Retrieves character set information as string using an ID
Retrieves character set and collation information based on the given MySQL ID.
Returns a tuple.
-
classmethod
get_info(setid)[source]¶ Retrieves character set information as tuple using an ID
Retrieves character set and collation information based on the given MySQL ID.
Raises ProgrammingError when character set is not supported.
Returns a tuple.
-
classmethod
get_supported()[source]¶ Retrieves a list with names of all supproted character sets
Returns a tuple.
-
slash_charsets= (1, 13, 28, 84, 87, 88)¶
-
-
class
mysql.connector.RefreshOption[source]¶ Bases:
mysql.connector.constants._ConstantsMySQL Refresh command options
Options used when sending the COM_REFRESH server command.
-
GRANT= 1¶
-
HOST= 8¶
-
LOG= 2¶
-
SLAVE= 64¶
-
STATUS= 16¶
-
TABLES= 4¶
-
THREADS= 32¶
-
desc= {'GRANT': (1, 'Refresh grant tables'), 'HOSTS': (8, 'Flush host cache'), 'LOG': (2, 'Start on new log file'), 'SLAVE': (64, 'Reset master info and restart slave thread'), 'STATUS': (16, 'Flush status variables'), 'TABLES': (4, 'close all tables'), 'THREADS': (32, 'Flush thread cache')}¶
-
-
exception
mysql.connector.Error(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
ExceptionException that is base class for all other error exceptions
-
exception
mysql.connector.InterfaceError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.ErrorException for errors related to the interface
-
exception
mysql.connector.DatabaseError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.ErrorException for errors related to the database
-
exception
mysql.connector.NotSupportedError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors when an unsupported database feature was used
-
exception
mysql.connector.DataError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors reporting problems with processed data
-
exception
mysql.connector.IntegrityError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors regarding relational integrity
-
exception
mysql.connector.ProgrammingError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors programming errors
-
exception
mysql.connector.OperationalError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors related to the database’s operation
-
exception
mysql.connector.InternalError(msg=None, errno=None, values=None, sqlstate=None)[source]¶ Bases:
mysql.connector.errors.DatabaseErrorException for errors internal database errors
-
mysql.connector.connect(*args, **kwargs)[source]¶ Create or get a MySQL connection object
In its simpliest form, Connect() will open a connection to a MySQL server and return a MySQLConnection object.
When any connection pooling arguments are given, for example pool_name or pool_size, a pool is created or a previously one is used to return a PooledMySQLConnection.
Returns MySQLConnection or PooledMySQLConnection.
-
mysql.connector.Date¶ alias of
datetime.date
-
mysql.connector.Time¶ alias of
datetime.time
-
mysql.connector.Timestamp¶ alias of
datetime.datetime
-
mysql.connector.Binary¶ alias of
builtins.bytes
-
mysql.connector.DateFromTicks(ticks)[source]