nick34992
2/4/2017 - 2:35 PM

MySQL Python connect() Function: Create Object for Database Connection. Automate Login.

MySQL Python connect() Function: Create Object for Database Connection. Automate Login.

MySQLdb.connect()

Use python-mysql to automate DB login.

import MySQLdb

[variable] = MySQLdb.connect([hostname], 
                             [username], 
                             [password], 
                             [database name])

Alternate:

[variable] = MySQLdb.connect(host="[hostname]",
                             user="[username]",
                             passwd="[password]",
                             db="[database name]")

Example:

db = MySQLdb.connect(host="localhost",
                     user="delta",
                     passwd="nQYWtdNQUugcb9ui",
                     db="menu")