Inserting data into MySQL My code currently doesn't insert data into MySQL fast enough. However I don't know how to measure the current speed.
def insert():
      mycursor = mydb.cursor()
      plik = input(&quot;:::&quot;)
      agefile = open(&quot;C:/Users/juczi/Desktop/New Folder/&quot; + plik, &quot;r&quot;)
      sql = &quot;INSERT INTO wyciek (nick, ip) VALUES (%s, %s)&quot;
      for row in agefile:
            mydb.commit()
            data = row.split(':')
            val = (data[0].replace(&quot;\n&quot;,&quot;&quot;), data[1].replace(&quot;\n&quot;, &quot;&quot;))
            mycursor.execute(sql, val)
      agefile.close()
If you are trying to insert data in bulk to Mysql the best would be to use LOAD DATA instead of doing it in a loop on top of an interpreted language, which is inevitably slower. However there is less flexibility if you need to transform data but that shouldn't be a problem in your case. All you're doing is get rid of carriage return. This is a plain delimited file without heavy transformation.
The mydb.commit() is misplaced. It should be called after running an insert/update. On the first iteration there is nothing to be committed.
But this is not efficient. I suggest that you take full advantage of transactions. Start a transaction at the beginning, do your loop and commit at the end. In case of error, you roll back. The added benefit is data integrity. If an error occurs, the data already inserted is &quot;undone&quot; so you don't end up with garbage due to a partial import of data.
Schema:
try:
    conn.autocommit = False

    # insert loop..

    # Commit your changes
    conn.commit()

except mysql.connector.Error as error:
    print(&quot;Failed to update record to database rollback: {}&quot;.format(error))
    # reverting changes because of exception
    conn.rollback()

See for example: Use Commit and Rollback to Manage MySQL Transactions in Python
This alone should improve performance but you have to test it to measure the gain.
Not performance-related, but you can also use a context manager whenever possible, for instance when opening/writing to a file. So:
agefile = open(&quot;C:/Users/juczi/Desktop/New Folder/&quot; + plik, &quot;r&quot;)

becomes:
with open(&quot;C:/Users/juczi/Desktop/New Folder/&quot; + plik, &quot;r&quot;) as agefile:
   # do something

and you don't have to bother closing the file, this is done automatically.