本文整理汇总了Python中MySQLdb.Connect方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLdb.Connect方法的具体用法?Python MySQLdb.Connect怎么用?Python MySQLdb.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySQLdb
的用法示例。
在下文中一共展示了MySQLdb.Connect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Connect [as 别名]
def __init__(self):
"""
DBhandler class constructor
"""
self.con = None
try:
self.con = mdb.Connect(host='localhost', user='stonixdb', passwd='He4vyKandi0ad', db='stonix')
if not self.con:
log_error("Failed to establish connection to stonix log database")
except Exception:
message = traceback.format_exc()
log_error(message)
sys.exit(1)
示例2: get_notepad_pages_mediawiki
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Connect [as 别名]
def get_notepad_pages_mediawiki(server, username, password, dbname,
base="IvreNotepad"):
"""Returns a list of the IP addresses for which a Mediawiki
page exists.
"""
ipaddr_page = '^' + re.escape(base) + '\\/\\d+\\.\\d+\\.\\d+\\.\\d+$'
cur = MySQLdb.Connect(server, username, password, dbname).cursor()
cur.execute("SELECT `page_title` FROM `wiki_page` WHERE `page_title` "
"REGEXP '%s'" % ipaddr_page)
return [page[0][len(base) + 1:] for page in cur]
示例3: getConnection
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Connect [as 别名]
def getConnection(self):
return MySQLdb.Connect(
host=self.DB_HOST,
port=self.DB_PORT,
user=self.DB_USER,
passwd=self.DB_PWD,
db=self.DB_NAME,
charset='utf8'
)
示例4: attempt_mysql_reconnect
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Connect [as 别名]
def attempt_mysql_reconnect():
"""Attempt to reconnect to MySQL
http://stackoverflow.com/a/29331237/865091
"""
import MySQLdb
conn = MySQLdb.Connect()
conn.ping(True)
示例5: _install_patches
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Connect [as 别名]
def _install_patches(self):
factory = ConnectionFactory(connect_func=MySQLdb.connect,
module_name='MySQLdb',
conn_wrapper_ctor=ConnectionWrapper)
MySQLdb.connect = factory
if hasattr(MySQLdb, 'Connect'):
MySQLdb.Connect = factory
示例6: _reset_patches
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Connect [as 别名]
def _reset_patches(self):
MySQLdb.connect = _MySQLdb_connect
if hasattr(MySQLdb, 'Connect'):
MySQLdb.Connect = _MySQLdb_connect
示例7: connectToUCSC
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Connect [as 别名]
def connectToUCSC(host="genome-mysql.cse.ucsc.edu",
user="genome",
database=None):
"""connect to UCSC database.
Arguments
---------
host : string
Host to connect to
user : string
Username to connect with
Database : string
database to use
Returns
-------
Database handle
"""
dbhandle = MySQLdb.Connect(host=host,
user=user)
cc = dbhandle.cursor()
cc.execute("USE %s " % database)
return dbhandle