Guest User

Untitled

a guest
Feb 8th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. > create table mytable (text varchar(200)) engine=InnoDB;
  2.  
  3. +-------+---------------+------+-----+---------+-------+
  4. | Field | Type | Null | Key | Default | Extra |
  5. +-------+---------------+------+-----+---------+-------+
  6. | text | varchar(2000) | YES | | NULL | |
  7. +-------+---------------+------+-----+---------+-------+
  8.  
  9. import _mysql
  10. import time
  11.  
  12. con = _mysql.connect('localhost', 'root', 'root', 'mydb')
  13.  
  14. stop = time.time()+1
  15.  
  16. while time.time() < stop: # runs loop for 1 sec
  17. con.query("INSERT into mytable VALUES('Test Data')")
  18.  
  19. 1. Tried to run the loop in 1 transaction.
  20. 2. Tried LOAD DATA INFILE 'new.txt' INTO TABLE mytable
  21.  
  22. import MySQLdb as mdb
  23. import time
  24.  
  25. #open file to insert data from
  26. #should be present in /var/lib/mysql/my_db folder
  27. file=open("new.txt")
  28. data = file.read()
  29.  
  30. #Credentials to connect to Server Database
  31. host = “localhost″
  32. username = “username”
  33. password = “password”
  34. db_name = “database_name”
  35. con=mdb.connect(host,username,password,db_name)
  36.  
  37. cur = con.cursor()
  38.  
  39. #setting time for 1 second
  40. stop = time.time()+1
  41.  
  42. #loop running for 1 second and insert values
  43. count=0
  44. while time.time() < stop:
  45. if cur.execute("LOAD DATA INFILE 'new.txt' INTO TABLE mytable"): count=count+1
  46.  
  47. #commit transaction
  48. con.commit()
  49.  
  50. #print number of rows inserted
  51. print count
Add Comment
Please, Sign In to add comment