Python does a program that needs to read data frequently and write data.
After a few days of running, I found that a MySQL link error occurred after a few hours of running, and the key error message is as follows:
2003, "Can" T connect to the MySQL server on ' 127.0.0.1 ' (10048)
Read some information, MySQL 10048 error is because the port is not enough to create a new link! The problem is the original link I have closed ah! The key is that the closed link, whose port is not immediately available, has a Windows default port cycle of 240 seconds.
Solution, from two aspects:
1. Increase available ports
Locate the Hkey_local_machine/system/currentcontrolset/services/tcpip/parameters registry subkey
and create a new REG_DWORD value named MaxUserPort
Set this value to decimal minimum 32768
The wait time for this value will be 30 seconds.
Reboot the Windows system.
Default value for this entry: 5000 (decimal)
2, shorten the port available time
Locate the Hkey_local_machine/system/currentcontrolset/services/tcpip/parameters registry subkey
and create a new REG_DWORD value named TcpTimedWaitDelay
Set this value to decimal 30, hexadecimal to 0x0000001e
The wait time for this value will be 30 seconds.
Default value for this entry: 0xF0 (16), wait time set to 240 seconds
and test the connection to MySQL.
code is as follows |
copy code |
Import MYSQLDB db = MySQLdb.connect (host= "localhost", user= "root", passwd= "root", db= "Slopeone") cursor = Db.cursor () F = open ("Sample.data", "R") for line in F: content = Line.rstrip (' \ n '). Split ("\ T") &N bsp; user_id = content[0] item_id = content[1] rating = content [2] print user_id,item_id,rating cursor.execute (insert INTO Oso_user_ Ratings VALUES (%s,%s,%s) ", (user_id,item_id,rating)) F.close () print" over! " |
The
is successful, and Reiki has been saved successfully.