There is a code to add to mysql :

 cursor.execute("SELECT id FROM keywords WHERE name = '%s', " % (channel_name)) 

When adding a value to a table in the name field, the id field is automatically filled. You need to get the id , which corresponds to the added variable channel_name

    1 answer 1

    With LIKE you search for the field (in my case, this field is real_name_test ) the values ​​that you entered in the name

     import pymysql name = input('Введите что то:\n') with pymysql.connect( host=host, port=3306, user=user, password=password, db="base", charset='utf8', autocommit=True) as cur: cur.execute("INSERT INTO Twiss (real_name_test) VALUES (%s)", (name,)) cur.execute("SELECT ID FROM Twiss WHERE real_name_test LIKE %s", (name,)) row = cur.fetchall() print('ID которое заполнилось = {}'.format(row[0][0])) 

    Conclusion

     Введите что то: Данный для заполнения SQL ID которое заполнилось = 65