mysql.connection.Connection

Package mysql :: Module connection :: Class Connection |
[hide private]
[frames] | no frames]

# Class Connection

    object --+
             |
            Connection

MySQL connection object.

Creating a new Connection object has the following parameters (all optional):

- `convert_in`: A mysql.conversion.input.Input_Conversion instance to use for input parameter conversion. If not specified, defaults to the implementation in the mysql.conversion.input module.

- `convert_out`: A mysql.conversion.output.Output_Conversion instance to use for output value conversion (when using the execute method to retrieve results, this does not apply to the statement API). If not specified, defaults to the implementation in the mysql.conversion.output module.

- `paramstyle`: The style of parameter substitution to use in the execute method. This may be one of the following:

  - `"format"`: Use simple Python format replacement, such as `"SELECT * FROM t WHERE x=%s AND y=%i"`.
  - `"pyformat"`: Use Python dictionary format replacement, such as `"SELECT * FROM t WHERE x=%(param1)s AND y=%(param2)i"`. You may pass in a mapping object as the next argument after the statement. When both a mapping object and keyword arguments are given and there are duplicates, the placeholders from the keyword arguments take precedence.
  - `"pytemplate"`: Use Python string Template substitution, such as `"SELECT * FROM t WHERE x=$param1 AND y=$param2"`. You may pass in a mapping object as the next argument after the statement. When both a mapping object and keyword arguments are given and there are duplicates, the placeholders from the keyword arguments take precedence.

  The default is `"pytemplate"`.

  See the mysql.conversion.input module for detail on how parameters are escaped.

Instance Methods | [hide private]
`` | __init__(...) x.__init__(...) initializes x; see x.__class__.__doc__ for signature
`` | __new__(T, S, ...) Returns a new object with type S, a subtype of T...
`` | _param_format(...) Convert args using simple python format replacement.
`` | _param_pyformat(...) Convert args using python dictionary format replacement.
`` | _param_pytemplate(...) Convert args using python string Template replacement.
`` | _raise_error(...) Raise the appropriate MySQL error exception from the current MySQL error.
`` | _set_unbuffered_statement(...) Set the current unbuffered statement object.
`` | add_init_command(...) Command to execute when connecting to the MySQL server.
`` | change_user(...) Switch user and current database.
`` | commit(...) Commit the current transaction.
`` | connect(...) Connect to the database.
`` | disable_multi_statements(...) Disable the use of multiple statements.
`` | disconnect(...) Disconnect from the database.
`` | enable_multi_statements(...) Enable the support for issuing multiple statements in one call.
`` | escape(...) Escape arguments for a SQL statement.
`` | exec_container(...) Execute a statement retrieving inputs from a container.
`` | exec_fetch_container(...) Execute a statement retrieving inputs and storing ouputs from/to a container.
`` | execute(...) Issue a SQL statement.
`` | get_client_info(...) Return the client version as a string.
`` | get_client_version(...) Return the client version as an integer.
`` | get_current_character_set_info(...) Return information about the current character set.
`` | get_host_info(...) Return information about the type of connection in use.
`` | get_protocol_version(...) Return the protocol used by the current connection.
`` | get_server_info(...) Return the server version as a string.
`` | get_server_version(...) Return the server version as an integer.
`` | has_more_results(...) Return whether or not more results are available.
`` | kill_server_thread(...) Asks the server to kill a thread.
`` | last_insert_id(...) Return the last AUTO_INCREMENT id.
`` | last_statement_info(...) Return an informational string about the last statement executed.
`` | new_statement(...) Create a new Statement object.
`` | next_result(...) Get the next result for multi-statement execution.
`` | ping(...) Check if the connection to the server is working.
`` | rollback(...) Roll back the current transaction.
`` | select_db(...) Set the database to use.
`` | server_thread_id(...) Return the server thread ID for the current connection.
`` | set_charset_dir(...) Set the pathname to the directory that contains character set definition files.
`` | set_charset_name(...) Set the name of the character set to use as the default character set.
`` | set_connect_timeout(...) Set the connect timeout in seconds.
`` | set_current_character_set(...) Set the current character set name.
`` | set_default_conf_file(...) Set the configuration file to load instead of `my.cnf`.
`` | set_default_conf_group(...) Set the group in my.cnf to read from.
`` | set_disable_load_infile(...) Disable the "LOAD DATA LOCAL INFILE" command.
`` | set_enable_local_infile(...) Enable the "LOAD DATA LOCAL INFILE" command.
`` | set_protocol_default(...) Use the default connection protocol.
`` | set_protocol_memory(...) Use the shared memory connection protocol.
`` | set_protocol_pipe(...) Use the named pipe connection protocol (Windows).
`` | set_protocol_socket(...) Use the socket connection protocol (Unix).
`` | set_protocol_tcp(...) Use the TCP connection protocol.
`` | set_read_timeout(...) Set the read timeout for communicating with the server.
`` | set_reconnect_off(...) Do not automatically reconnect when the connection to the server is lost.
`` | set_reconnect_on(...) Automatically reconnect when the connection to the server is lost.
`` | set_secure_auth_off(...) Allow you to connect to servers that do not support the password hashing used in MySQL 4.1.1 and later.
`` | set_secure_auth_on(...) Only connect to servers that support the password hashing used in MySQL 4.1.1 and later.
`` | set_shared_memory_base_name(...) Set the name of the shared memory object for communicating with the server.
`` | set_use_compression(...) Use the compressed client/server protocol.
`` | set_write_timeout(...) Set the write timeout for communicating with the server.
`` | shutdown_server(...) Ask the server to shut down.
`` | sqlstate(...) Return the current SQL state.
`` | ssl_set(...) Set SSL parameters for the connection.
`` | status(...) Return a status string.
`` | warning_count(...) Return the number of warnings generated by the previous SQL statement.
Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__str__`

Class Variables | [hide private]
`` | __pyx_vtable__ = `<PyCObject object at 0x852e080>`

Instance Variables | [hide private]
`` | _convert_in = `<member '_convert_in' of 'mysql.connection.Connectio...` mysql.conversion.input.Input_Conversion instance.
`` | _convert_out = `<member '_convert_out' of 'mysql.connection.Connecti...` mysql.conversion.output.Output_Conversion instance.
`` | _db MYSQL database structure.
`` | _old_statements A _Statement_Cleaner instance for cleaning up statement structures.
`` | _param_formatter The `_param_*` method to call to format parameters based on the `paramstyle` argument given in `__init__`.
`` | _unbuffered_result A live mysql.result.Result instance that is not buffering results on the client side.
`` | _unbuffered_statement A list mysql.stmt.Statement instance that is currently retrieving results without buffering them on the client side.
`` | connected = `<member 'connected' of 'mysql.connection.Connection'...` Boolean value that indicates whether or not the connection is currently established.
`` | paramstyle = `<member 'paramstyle' of 'mysql.connection.Connection...` The paramstyle string passed in the constructor.

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(...) (Constructor) |
x.__init__(...) initializes x; see x.__class__.__doc__ for signature Overrides: object.__init__

### __new__(T, S, ...) |
    Returns:
        a new object with type S, a subtype of T
Overrides: object.__new__

### _param_format(...) |
Convert args using simple python format replacement.

### _param_pyformat(...) |
Convert args using python dictionary format replacement.

### _param_pytemplate(...) |
Convert args using python string Template replacement.

### _raise_error(...) |
Raise the appropriate MySQL error exception from the current MySQL error. If there is no error, then mysql.exceptions.client.Unknown_Error is raised. Never call this when self._db is NULL.

### _set_unbuffered_statement(...) |
Set the current unbuffered statement object. This is used to keep track of which mysql.stmt.Statement object is currently live with unbuffered results. It removes the previously set Statement object.

### add_init_command(...) |
Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting (when set_reconnect_on is used). You may call this multiple times to add multiple commands. Closing a connection will clear any init commands registered. The arguments and keyword arguments behave the same as the execute method paying attention to the `paramstyle` specified when creating the connection object. Note that this will not allow NUL characters in the statement or values. Parameters: `statement` - The SQL command to execute.

### change_user(...) |
Switch user and current database. If the user cannot be authenticated or does not have permissions, the current user and database are not changed. This command always performs a ROLLBACK of any active transactions, closes all temporary tables, unlocks all locked tables and resets the state as if one had done a new connect. This happens even if the user didn't change. Note: This will close any live unbuffered result objects and reset any live statement objects. Parameters: `user` - The user to log in as. If not specified, defaults to the current user. `password` - The password to use. If not specified, only entries in the MySQL `user` table with a blank password will work. `db` - The database to use. If not specified, no database is selected and you must use the select_db method. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error. `mysql.exceptions.Access_Denied_Error` - The user or password was wrong. `mysql.exceptions.Bad_DB_Error` - The database didn't exist. `mysql.exceptions.DB_Access_Denied_Error` - The user did not have access rights to the database. `mysql.exceptions.Wrong_DB_Name` - The database name was too long.

### commit(...) |
Commit the current transaction. If no transaction is in progress, this does nothing. Note that the default mode of a connection is "autocommit" which makes this command not needed. Note: This will close any live unbuffered result objects and reset any live statement objects. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### connect(...) |
Connect to the database. Warning If a connection is already established, it will be closed and a new one created. Doing this will invalidate any live unbuffered result object or Statement objects. It also clears all state of the Connection object, including any options you have given previously, as-if a new Connection object was created. Parameters: `host` - The host to connect to. If not specified, defaults to the local host. `user` - The user to log in as. If not specified, defaults to the current user. `password` - The password to use. If not specified, only entries in the MySQL `user` table with a blank password will work. `db` - The database to use. If not specified, no database is selected and you must use the select_db method. `port` - The port to use for TCP/IP connections. You must call set_protocol_tcp to use this option. `unix_socket` - The named pipe to use for the connection. `clientflag` - A bitwise-or of flags to use. The following are defined in mysql.constants.client_flags: `COMPRESS`: Use compression protocol. `FOUND_ROWS`: Return the number of found (matched) rows, not the number of affected rows. `IGNORE_SPACE`: Allow spaces after function names. Makes all functions names reserved words. `INTERACTIVE`: Allow interactive_timeout seconds (instead of wait_timeout seconds) of inactivity before closing the connection. The client's session wait_timeout variable is set to the value of the session interactive_timeout variable. `LOCAL_FILES`: Enable LOAD DATA LOCAL handling. `MULTI_STATEMENTS`: Tell the server that the client may send multiple statements in a single string (separated by `;`). If this flag is not set, multiple-statement execution is disabled. `MULTI_RESULTS`: Tell the server that the client can handle multiple result sets from multiple-statement executions or stored procedures. This is automatically set if MULTI_STATEMENTS is set. `NO_SCHEMA`: Don't allow the db_name.tbl_name.col_name syntax. This is for ODBC. It causes the parser to generate an error if you use that syntax, which is useful for trapping bugs in some ODBC programs. `ODBC`: The client is an ODBC client. This changes mysqld to be more ODBC-friendly. Raises: `mysql.exceptions.MySQL_Error` - Generic MySQL error. `mysql.exceptions.Conn_Host_Error` - Failed to connect to the My_SQL server. `mysql.exceptions.Connection_Error` - Failed to connect to the local My_SQL server. `mysql.exceptions.IP_Sock_Error` - Failed to create an IP socket. `mysql.exceptions.Socket_Create_Error` - Failed to create a Unix socket. `mysql.exceptions.Unknown_Host` - Failed to find the IP address for the hostname. `mysql.exceptions.Version_Error` - A protocol mismatch resulted from attempting to connect to a server with a client library that uses a different protocol version. This can happen if you use a very old client library to connect to a new server that wasn't started with the --old-protocol option. `mysql.exceptions.Named_Pipe_Open_Error` - Failed to create a named pipe on Windows. `mysql.exceptions.Named_Pipe_Wait_Error` - Failed to wait for a named pipe on Windows. `mysql.exceptions.Named_Pipe_Set_State_Error` - Failed to get a pipe handler on Windows. `mysql.exceptions.Server_Lost` - If connect_timeout > 0 and it took longer than connect_timeout seconds to connect to the server or if the server died while executing the init-command. `mysql.exceptions.Access_Denied_Error` - The user or password was wrong. `mysql.exceptions.Bad_DB_Error` - The database didn't exist. `mysql.exceptions.DB_Access_Denied_Error` - The user did not have access rights to the database. `mysql.exceptions.Wrong_DB_Name` - The database name was too long.

### disable_multi_statements(...) |
Disable the use of multiple statements. Note: This will close any live unbuffered result objects and reset any live statement objects. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### disconnect(...) |
Disconnect from the database. Warning This will invalidate any live, unbuffered result objects and Statement objects! It also clears all state of the Connection object, including any options you have given, as-if a new Connection object was created. This never fails.

### enable_multi_statements(...) |
Enable the support for issuing multiple statements in one call. Multiple statements can be seperated with a semicolon (;). This can also be enabled with the MULTI_STATEMENTS flag in the connect call. The execute method will return the first result. To get additional results, call the next_result method. Note: This will close any live unbuffered result objects and reset any live statement objects. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### escape(...) |
Escape arguments for a SQL statement. This performs the same argument substitution and character escaping that the execute method uses. The arguments and keyword arguments behave the same as the execute method paying attention to the `paramstyle` specified when creating the connection object. Parameters: `statement` - The SQL command to escape. Returns: Returns the statement as a string with the arguments included and properly escaped.

### exec_container(...) |
Execute a statement retrieving inputs from a container. This method is similar to the execute method, except it gets its inputs from a container object instead as method parameters. The paramstyle must by "pytemplate". The variable names are obtained from the statement. It uses `getattr` to obtain the values from the `container` object. Parameters: `container` - The object to look for the input parameters. `statement` - The SQL statement to issue. `store_result` - Whether or not to fetch the entire result from the server imediately for SELECT-like queries. The default is False. See the execute method for more detail. Returns: Returns a mysql.result.Result object for SELECT-like queries, otherwise returns the number of rows affected. See the execute method for more detail. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### exec_fetch_container(...) |
Execute a statement retrieving inputs and storing ouputs from/to a container. This method is similar to the execute method, except it gets its inputs from a container object instead as method parameters. The output for one row is stored in the container object. The paramstyle must by "pytemplate". The variable names are obtained from the statement. It uses `getattr` to obtain the values from the `container` object and `setattr` to set them. If a column name is aliased with "AS", then the aliased name will be used for setting the value in the container. Parameters: `container` - The object to look for the input parameters and to set the output. `statement` - The SQL statement to issue. `store_result` - Whether or not to fetch the entire result from the server imediately for SELECT-like queries. The default is False. See the execute method for more detail. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error. `mysql.exceptions.No_More_Rows` - There are no more rows left.

### execute(...) |
Issue a SQL statement. Additional arguments and keywords are used for parameter substitution in the statement. How these are used depends on the `paramstyle` parameter used when creating the Connection object. Beware that the keyword `store_result` is not available for use since it is used by this function. Parameters: `statement` - The SQL statement to issue. `store_result` - Whether or not to fetch the entire result from the server immediately for SELECT-like queries. If False, results will be fetched from the server on an as-needed basis. Defaults to False. Note that some methods in the Result object are not available if this is False. Beware that setting this to True may use a lot of memory. However, setting this to False will tie up server resources, thus you shouldn't do that if you may be taking a long time to fetch the results. Note: You can only have 1 live "unbuffered" (False) result set at once. You must fetch all rows (until `No_More_Rows` is raised) or call `close` on the result before executing another statement. If you do not do that, then this method will automatically call `close` on your old result object for you! Several other methods in the Connection and Statement objects will also force a close. This is indicated in those method's docstrings. Returns: Returns a mysql.result.Result object for SELECT-like queries (SELECT, SHOW, DESCRIBE, EXPLAIN), otherwise returns the number of rows affected. Rows "affected" is defined as rows that were actually modified by an UPDATE, INSERT, or DELETE statement. All other statements return zero. Note that when you use a REPLACE command, this returns 2 if the new row replaced an old row. This is because in this case one row was inserted after the duplicate was deleted. If you use INSERT ... ON DUPLICATE KEY UPDATE to insert a row, this returns 1 if the row is inserted as a new row and 2 if an existing row is updated. If you specify the flag CLIENT_FOUND_ROWS when connecting, this returns the number of rows matched by the WHERE statement for UPDATE statements, not the number of rows actually modified. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### get_client_info(...) |
Return the client version as a string. Returns: Returns a string that represents the client library version (such as '5.0.15').

### get_client_version(...) |
Return the client version as an integer. Returns: Returns an integer that has the format XYYZZ where X is the major version, YY is the release level, and ZZ is the version number within the release level. For example, a value of 50015 represents a client library version of 5.0.15

### get_current_character_set_info(...) |
Return information about the current character set. Returns: Returns a Character_Set object of the current connection.

### get_host_info(...) |
Return information about the type of connection in use. Returns: Returns a string that describes the current connection. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect.

### get_protocol_version(...) |
Return the protocol used by the current connection. Returns: Returns an integer of the current protocol version. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect.

### get_server_info(...) |
Return the server version as a string. Returns: Returns a string that represents the server version (such as '5.0.15'). Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect.

### get_server_version(...) |
Return the server version as an integer. Returns: Returns an integer that has the format XYYZZ where X is the major version, YY is the release level, and ZZ is the version number within the release level. For example, a value of 50015 represents a server version of 5.0.15 Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect.

### has_more_results(...) |
Return whether or not more results are available. This is used for multiple-statement execution. You can call this method to check if more results are available. Returns: Returns a boolean of whether or not more results are available. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect.

### kill_server_thread(...) |
Asks the server to kill a thread. Note: This will close any live unbuffered result objects and reset any live statement objects. Parameters: `thread_id` - The thread ID to kill. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### last_insert_id(...) |
Return the last AUTO_INCREMENT id. Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement. Use this method after you have performed an INSERT statement into a table that contains an AUTO_INCREMENT field. More precisely, the last insert ID is updated under these conditions: INSERT statements that store a value into an AUTO_INCREMENT column. This is true whether the value is automatically generated by storing the special values NULL or 0 into the column, or is an explicit non-special value. In the case of a multiple-row INSERT statement, this returns the first automatically generated AUTO_INCREMENT value; if no such value is generated, it returns the last last explicit value inserted into the AUTO_INCREMENT column. INSERT statements that generate an AUTO_INCREMENT value by inserting LAST_INSERT_ID(expr) into any column. INSERT statements that generate an AUTO_INCREMENT value by updating any column to LAST_INSERT_ID(expr). The value is not affected by statements such as SELECT that return a result set. If the previous statement returned an error, the value is undefined. Note that this raises No_Insert_ID_Error if the previous statement does not use an AUTO_INCREMENT value. If you need to save the value for later, be sure to call last_insert_id immediately after the statement that generates the value. The value is affected only by statements issued within the current client connection. It is not affected by statements issued by other clients. Also note that the value of the SQL LAST_INSERT_ID() function always contains the most recently generated AUTO_INCREMENT value, and is not reset between statements because the value of that function is maintained in the server. Another difference is that LAST_INSERT_ID() is not updated if you set an AUTO_INCREMENT column to a specific non-special value. The reason for the difference between LAST_INSERT_ID() and last_insert_id is that LAST_INSERT_ID() is made easy to use in scripts while last_insert_id tries to provide a little more exact information of what happens to the AUTO_INCREMENT column. Returns: Returns an integer of the last insert id. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.No_Insert_ID_Error` - The last insert ID is not available.

### last_statement_info(...) |
Return an informational string about the last statement executed. The format of the string varies depending on the type of query, as described here. The numbers are illustrative only; the string contains values appropriate for the query. `INSERT INTO ... SELECT ...` String format: `Records: 100 Duplicates: 0 Warnings: 0` `INSERT INTO ... VALUES (...),(...),(...)...` String format: `Records: 3 Duplicates: 0 Warnings: 0` NOTE: Only returns information for the multiple-row form of the statement. `LOAD DATA INFILE ...` String format: `Records: 1 Deleted: 0 Skipped: 0 Warnings: 0` `ALTER TABLE` String format: `Records: 3 Duplicates: 0 Warnings: 0` `UPDATE` String format: `Rows matched: 40 Changed: 40 Warnings: 0` Returns: Returns a string describing the last statement executed. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.No_Statement_Info_Error` - Information is not available for the last statement.

### new_statement(...) |
Create a new Statement object. See mysql.stmt for more detail on using the statement API. Parameters: `statement` - The SQL statement. Returns: Returns a new mysql.stmt.Statement object.

### next_result(...) |
Get the next result for multi-statement execution. When executing multiple statements at once, the execute method will return the first result for the first statement. You may then call this method repeatedly to get the next result. See the module docstring for more detail about handling multiple results. See the execute method for more detail about the return value. Note: This will close any live unbuffered result objects and reset any live statement objects. Parameters: `store_result` - Whether or not to fetch the entire result from the server immediately for SELECT-like queries. If False, results will be fetched from the server on an as-needed basis. Defaults to False. Returns: Returns a mysql.result.Result object or a number of rows affected. Raises: `mysql.exceptions.No_More_Results` - No more results are available. `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### ping(...) |
Check if the connection to the server is working. If the connection has gone down, an automatic reconnection is attempted (if set_reconnect_on is used). This function can be used by clients that remain idle for a long while, to check whether the server has closed the connection and reconnect if necessary. Note: This will close any live unbuffered result objects and reset any live statement objects. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### rollback(...) |
Roll back the current transaction. If no transaction is in progress, this does nothing. Note that the default mode of a connection is "autocommit" which makes this command not needed. Note: This will close any live unbuffered result objects and reset any live statement objects. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### select_db(...) |
Set the database to use. Note: This will close any live unbuffered result objects and reset any live statement objects. Parameters: `database` - The name of the database. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### server_thread_id(...) |
Return the server thread ID for the current connection. The thread ID may be used with the kill_server_thread method. Note that some methods may cause an automatic reconnection attempt, which causes the thread ID to change. This means you should not get the thread ID and store it for later. You should get it when you need it. Returns: Returns the thread ID. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect.

### set_charset_dir(...) |
Set the pathname to the directory that contains character set definition files. Will only take effect on the next connection attempt. Parameters: `directory` - The directory of character set definition files.

### set_charset_name(...) |
Set the name of the character set to use as the default character set. Will only take effect on the next connection attempt. Parameters: `charset` - The default character set to use.

### set_connect_timeout(...) |
Set the connect timeout in seconds. Will only take effect on the next connection attempt. Parameters: `timeout` - The connect timeout in seconds.

### set_current_character_set(...) |
Set the current character set name. This is similar to the SET NAMES statement. The connection collation becomes the default collation of the character set. Note: This will close any live unbuffered result objects and reset any live statement objects. Parameters: `name` - The name of the character set to use. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### set_default_conf_file(...) |
Set the configuration file to load instead of `my.cnf`. Will only take effect on the next connection attempt. Parameters: `filename` - The file name to load the options from.

### set_default_conf_group(...) |
Set the group in my.cnf to read from. Will only take effect on the next connection attempt. Parameters: `group_name` - The name of the group from the configuration file.

### set_disable_load_infile(...) |
Disable the "LOAD DATA LOCAL INFILE" command. Will only take effect on the next connection attempt. See notes in set_enable_local_infile for more detail.

### set_enable_local_infile(...) |
Enable the "LOAD DATA LOCAL INFILE" command. Will only take effect on the next connection attempt. This option is only available if your MySQL installation was compiled to support it (with --enable-local-infile) and the MySQL server or client configuration files have not explicitly disabled its support (with --local-infile=0). If it is not supported, you will get a mysql.exceptions.Not_Allowed_Command exception when you try to execute the statement.

### set_protocol_default(...) |
Use the default connection protocol. Will only take effect on the next connection attempt.

### set_protocol_memory(...) |
Use the shared memory connection protocol. Will only take effect on the next connection attempt.

### set_protocol_pipe(...) |
Use the named pipe connection protocol (Windows). Will only take effect on the next connection attempt.

### set_protocol_socket(...) |
Use the socket connection protocol (Unix). Will only take effect on the next connection attempt.

### set_protocol_tcp(...) |
Use the TCP connection protocol. Will only take effect on the next connection attempt.

### set_read_timeout(...) |
Set the read timeout for communicating with the server. Will only take effect on the next connection attempt. Parameters: `timeout` - The read timeout in seconds.

### set_reconnect_off(...) |
Do not automatically reconnect when the connection to the server is lost. This is the default. This must be called after a connection is established. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect.

### set_reconnect_on(...) |
Automatically reconnect when the connection to the server is lost. Note that it will not attempt to reconnect if the connection is in the middle of a transaction. Calls that need to interact with the server will immediately raise mysql.exceptions.Server_Gone_Error. This must be called after a connection is established. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect.

### set_secure_auth_off(...) |
Allow you to connect to servers that do not support the password hashing used in MySQL 4.1.1 and later. Will only take effect on the next connection attempt. This is the default (unless overridden by a configuration file).

### set_secure_auth_on(...) |
Only connect to servers that support the password hashing used in MySQL 4.1.1 and later. Will only take effect on the next connection attempt.

### set_shared_memory_base_name(...) |
Set the name of the shared memory object for communicating with the server. Will only take effect on the next connection attempt. Parameters: `base_name` - The name of the shared memory object.

### set_use_compression(...) |
Use the compressed client/server protocol. Will only take effect on the next connection attempt.

### set_write_timeout(...) |
Set the write timeout for communicating with the server. Will only take effect on the next connection attempt. Parameters: `timeout` - The write timeout in seconds.

### shutdown_server(...) |
Ask the server to shut down. You must have SHUTDOWN privileges to run this command. Note: This will close any live unbuffered result objects and reset any live statement objects. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### sqlstate(...) |
Return the current SQL state. The error code consists of five characters. '00000' means "no error". The values are specified by ANSI SQL and ODBC. Note that not all MySQL errors are mapped to SQLSTATE error codes. The value 'HY000' (general error) is used for unmapped errors. Returns: Returns a 5-character string.

### ssl_set(...) |
Set SSL parameters for the connection. This applies to the next call to connect. Errors are not returned until you try to connect. All parameters are optional. Parameters: `key` - The pathname to the key file. `cert` - The pathname to the certificate file. `ca` - The pathname to the certificate authority file. `capath` - The pathname to a directory that contains trusted SSL CA certificates in pem format. `cipher` - A list (comma separated string) of allowable ciphers to use for SSL encryption.

### status(...) |
Return a status string. This returns information similar to that provided by the `mysqladmin status` command. This includes uptime in seconds and the number of running threads, questions, reloads, and open tables. Note: This will close any live unbuffered result objects and reset any live statement objects. Returns: Returns a status string. Raises: `mysql.exceptions.Not_Connected_Error` - Method was called before calling connect. `mysql.exceptions.MySQL_Error` - Generic MySQL error.

### warning_count(...) |
Return the number of warnings generated by the previous SQL statement. Issue the SHOW WARNINGS statement to see what the warnings actually are. Returns: Returns an integer of the number of warnings generated by the previous SQL statement.

Class Variable Details | [hide private]

    ### __pyx_vtable__ Value:
        <PyCObject object at 0x852e080>

Instance Variable Details | [hide private]

    ### _convert_in mysql.conversion.input.Input_Conversion instance. (Read only.) Value:
        <member '_convert_in' of 'mysql.connection.Connection' objects>

    ### _convert_out mysql.conversion.output.Output_Conversion instance. (Read only.) Value:
        <member '_convert_out' of 'mysql.connection.Connection' objects>

### _db MYSQL database structure. May be NULL. (C only.)

### _old_statements A _Statement_Cleaner instance for cleaning up statement structures. (C only).

### _param_formatter The `_param_*` method to call to format parameters based on the `paramstyle` argument given in `__init__`. (C only.)

### _unbuffered_result A live mysql.result.Result instance that is not buffering results on the client side. This is monitored so that it can be closed whenever an operation is performed that would reset the state of the connection. (C only.)

### _unbuffered_statement A list mysql.stmt.Statement instance that is currently retrieving results without buffering them on the client side. This is monitored so that it can be closed whenever an operation is performed that would reset the state of the connection. (C only.)

    ### connected Boolean value that indicates whether or not the connection is currently established. (Read only.) Value:
        <member 'connected' of 'mysql.connection.Connection' objects>

    ### paramstyle The paramstyle string passed in the constructor. Value:
        <member 'paramstyle' of 'mysql.connection.Connection' objects>