Python MySQLdb.Connect() Examples

The following are 8 code examples of MySQLdb.Connect(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module MySQLdb , or try the search function .
Example #1
Source File: stonixImporter.py    From stonix with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #2
Source File: utils.py    From ivre with GNU General Public License v3.0 5 votes vote down vote up
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] 
Example #3
Source File: count_data.py    From BackManager with Apache License 2.0 5 votes vote down vote up
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'
                           ) 
Example #4
Source File: wechat_sms.py    From BackManager with Apache License 2.0 5 votes vote down vote up
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'
                           ) 
Example #5
Source File: db.py    From django-htk with MIT License 5 votes vote down vote up
def attempt_mysql_reconnect():
    """Attempt to reconnect to MySQL
    http://stackoverflow.com/a/29331237/865091
    """
    import MySQLdb
    conn = MySQLdb.Connect()
    conn.ping(True) 
Example #6
Source File: mysqldb.py    From opentracing-python-instrumentation with MIT License 5 votes vote down vote up
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 
Example #7
Source File: mysqldb.py    From opentracing-python-instrumentation with MIT License 5 votes vote down vote up
def _reset_patches(self):
        MySQLdb.connect = _MySQLdb_connect
        if hasattr(MySQLdb, 'Connect'):
            MySQLdb.Connect = _MySQLdb_connect 
Example #8
Source File: PipelineGtfsubset.py    From CGATPipelines with MIT License 5 votes vote down vote up
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