'Repeat connection attempts to server until we get a valid connection.'

def _MakeConnection(self, database=''):

    first_attempt_time = time.time()
    wait_time = config.CONFIG['Mysql.max_connect_wait']
    while ((wait_time == 0) or ((time.time() - first_attempt_time) < wait_time)):
        try:
            connection_args = dict(user=config.CONFIG['Mysql.database_username'], db=database, charset='utf8', passwd=config.CONFIG['Mysql.database_password'], cursorclass=cursors.DictCursor, host=config.CONFIG['Mysql.host'], port=config.CONFIG['Mysql.port'])
            dbh = MySQLdb.connect(**connection_args)
            return dbh
        except MySQLdb.OperationalError as e:
            if ('Access    denied' in str(e)):
                raise Error(str(e))
            if ("Can't    connect" in str(e)):
                logging.warning('Datastore    connection    retrying    after    failed    with    %s.', str(e))
                time.sleep(0.5)
                continue
            raise
    raise IOError('Unable    to    connect    to    Mysql    database.')
