Python3 and MYSQL - Using Variables


I am getting nuts with using Variables for certain MYSQL Statements. Let me explain what I am trying to do:

Step 1: I want to get the ID and NAME from a certain Table (this works)

Step 2: I want to hand the NAME of Step 1 into a SELECT statement in order to get all the IDs from another table which CONTAIN the NAME from my Variable (Here I am facing problems with Tuples from the Output of Step1)

Step 3: Then I want to use all the IDs from Step 2 to UPDATE several fields of each ID with Values

Here is the code I am experimenting:

    connection = mysql.connector.connect(host=os.getenv("DB_HOST"),

    database = os.getenv("DB_DATABASE")

    if connection.is_connected():
        print('Connected to MySQL database named => ' + database)

    # STEP 1: Call and get ID & NAME for each KeywordGroup from Table
    cursor = connection.cursor(buffered=True)
    sql_select_Query = "select id, name from keyword_group where language_id = 1"
    aKeywordGroup = cursor.fetchmany(10)

    while i< len(aKeywordGroup):
        kw = aKeywordGroup[i]
        sKeywordGroupName = kw[-1]

    # STEP 2: Call Keyword and get ID and Name where KWG exist
    for name in enumerate(sKeywordGroupName):
        cursor = connection.cursor(buffered=True)
        sql_select_Query = """select id, name from keyword where name like %s"""
        cursor.execute(sql_select_Query, [sKeywordGroupName])
        all_keywords = cursor.fetchmany(10)


No matter how I format the output of Step 2 I get or no result or 1o times the same result.

Any idea where my mistake is?

Thanks for your help as I am really stuck here

i put your code:

and set up some mocks, so i run your code without going through the trouble of configuring everything.

Any change i can get a small data sample to see what i am dealing with?

i could simple be the pattern matching: