Name

MySQL.connect()

Signature

                        connection = MySQL.connect(params)

Synopsis

Connects to the MySQL database engine represented by the various connection keyword/value parameters. These parameters include:

host

The name of the server on which the MySQL database is running

user

The user ID for connecting to MySQL. MySQL should allow this user to make the connection.

passwd

The password to authenticate the user ID for the connection.

db

The MySQL database to which the application attempts to connect.

port

Directs MySQLdb to connect to a MySQL installation on a custom part. When left unspecified, the method will use the default MySQL port of 3306.

unix_socket

Identifies the location of a socket or named pipe to use if the host allows it.

client_flags

An integer specifying the client connection flags to use. These client connection flags are the same ones enumerated in Chapter 19 for the mysql_real_connect( ) method.

This method returns a Python object representing a connection to a MySQL database.

Example

connection = MySQLdb.connect(host='carthage', user='test', 
                             passwd='test', db='test');

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.