Example #1
0
def mysql_conn_string(conn):
    param = conn.parameterValues
    if conn.driver.name == "MysqlNative":
        return "%(userName)s@%(hostName)s:%(port)s" % param
    elif conn.driver.name == "MysqlNativeSocket":
        if not param.get('socket', False):
            try:
                connection = db_utils.MySQLConnection(
                    conn, password=request_password(conn))
                connection.connect()
            except (NotConnectedError, db_utils.MySQLError):
                raise Exception(
                    'There is no connection to the target MySQL server and the socket parameter in your '
                    'target connection settings is blank. Please check that your target server is running '
                    'or go back to the Target Selection page and set the socket parameter there.'
                )

            result = connection.executeQuery("SHOW VARIABLES LIKE 'socket';")
            if result and result.nextRow():
                socket = result.stringByName('Value')
                param = {'userName': param['userName'], 'socket': socket}
                connection.disconnect()
            else:
                raise Exception(
                    'Failed while querying the socket server variable and the socket parameter in your '
                    'target connection settings is blank. Please go back to the Target Selection page and '
                    'make sure that you have the socket parameter set.')

        return "%(userName)s@::%(socket)s" % param
    else:
        raise Exception(
            "Connection method type %s is not supported for migration" %
            conn.driver.name)
Example #2
0
def connect(connection, password):
    try:
        con = get_connection(connection)
        try:
            con.ping()
        except Exception:
            grt.send_info("Reconnecting to %s..." % connection.hostIdentifier)
            con.disconnect()
            con.connect()
            grt.send_info("Connection restablished")
    except NotConnectedError:
        con = db_utils.MySQLConnection(connection, password=password)
        grt.send_info("Connecting to %s..." % connection.hostIdentifier)
        con.connect()
        grt.send_info("Connected")
        _connections[connection.__id__] = con
    return 1