Install Python to operate MySQL driver MySQLdb first.
Work needs to add test data to MySQL. Read the introduction on the net, feel very fun. Google took a look, and then changed a small program. This little program has inspired me to have a lot of interest in Python. So keep a record and always motivate yourself.
Yum Install mysql-python.x86_64
#!/usr/bin/env python
#coding: Utf-8
Import MySQLdb
conn = MySQLdb.connect (host= ' 192.168.5.25 ', user= ' testuser ', passwd= ' test ')
cursor = Conn.cursor ()
conn.select_db (' TestDB ')
Import datetime
StartTime = Datetime.datetime.now ()
Print StartTime
For ID in range (100000):
values = []
For I in range (40):
Values.append ((i+id*40, ' Test ' + str (I+ID*40)))
Cursor.executemany ("" "INSERT into test values (%s,%s)" ", values)
Conn.commit ()
Cursor.close ()
Endtime = Datetime.datetime.now ()
Print Endtime
Print (endtime-starttime). seconds
Python operation MySQL