MySQL Utilities 1.4 Manual  /  ...  /  Specifying Connections in Python Library

2.2.2. Specifying Connections in Python Library

If you build your own utilities using the MySQL Utilities library, you will encounter various methods for connecting to MySQL servers. Methods that deal with connecting to servers can accept the following mechanisms for supplying the data.

  • As a Python dictionary containing the connection parameters.

  • As a connection specification string containing the connection parameters.

  • As a Server instance.

The dictionary lists the values by name as described above. For example, you would create code like the following.

# Set connection values
dest_values = {
    "user" : "root",
    "passwd" : "secret",
    "host" : "localhost",
    "port" : 3308,
    "unix_socket" : None,
}

The connection specification is a string the form <user>[:<passwd>]@<host>[:<port>][:<socket>] where the passwd, port, and socket are optional. This string is parsed using the options.parse_connection function.

You can also specify an existing instance of the Server class. In this case, the new class will copy the connection information.


User Comments
Sign Up Login You must be logged in to post a comment.