Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- > create table mytable (text varchar(200)) engine=InnoDB;
- +-------+---------------+------+-----+---------+-------+
- | Field | Type | Null | Key | Default | Extra |
- +-------+---------------+------+-----+---------+-------+
- | text | varchar(2000) | YES | | NULL | |
- +-------+---------------+------+-----+---------+-------+
- import _mysql
- import time
- con = _mysql.connect('localhost', 'root', 'root', 'mydb')
- stop = time.time()+1
- while time.time() < stop: # runs loop for 1 sec
- con.query("INSERT into mytable VALUES('Test Data')")
- 1. Tried to run the loop in 1 transaction.
- 2. Tried LOAD DATA INFILE 'new.txt' INTO TABLE mytable
- import MySQLdb as mdb
- import time
- #open file to insert data from
- #should be present in /var/lib/mysql/my_db folder
- file=open("new.txt")
- data = file.read()
- #Credentials to connect to Server Database
- host = “localhost″
- username = “username”
- password = “password”
- db_name = “database_name”
- con=mdb.connect(host,username,password,db_name)
- cur = con.cursor()
- #setting time for 1 second
- stop = time.time()+1
- #loop running for 1 second and insert values
- count=0
- while time.time() < stop:
- if cur.execute("LOAD DATA INFILE 'new.txt' INTO TABLE mytable"): count=count+1
- #commit transaction
- con.commit()
- #print number of rows inserted
- print count
Add Comment
Please, Sign In to add comment