Python MySQLdb.Connect() Examples

The following are 8 code examples for showing how to use MySQLdb.Connect(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module MySQLdb , or try the search function .

Example 1
Project: stonix   Author: CSD-Public   File: stonixImporter.py    License: 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
Project: ivre   Author: cea-sec   File: utils.py    License: 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
Project: BackManager   Author: linuxyan   File: count_data.py    License: 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
Project: BackManager   Author: linuxyan   File: wechat_sms.py    License: 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
Project: django-htk   Author: hacktoolkit   File: db.py    License: 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
Project: opentracing-python-instrumentation   Author: uber-common   File: mysqldb.py    License: 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
Project: opentracing-python-instrumentation   Author: uber-common   File: mysqldb.py    License: 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
Project: CGATPipelines   Author: CGATOxford   File: PipelineGtfsubset.py    License: 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