0
votes
# -*- coding: utf-8 -*-
import MySQLdb
import sitedb

for i in range(5):
    print i
    cred = sitedb.loadmysqlcredential()
    db = MySQLdb.connect(host = cred["host"], user = cred["user"], passwd = cred["passwd"], db = "vg_site_db", charset = 'utf8')
    db.close()

I have MySQL at the different servers: Windows and Linux. At the Win this code work correct. At the Linux on the third iterate mysql sad: Lost connection to MySQL server at 'reading initial communication packet', system error: 0.

What I have to change at the Linux server?

UPD:

The problem is that I have loop (for), and when i = 0 connection happen, also like i = 1 and 2, but next the connection blocked

2

2 Answers

0
votes

The following is an example of a conneection string I use against a linux db, hope it helps:

 dbSomeDBConnection = MySQLdb.connect(host="10.100.10.2",
                      user="root",
                      passwd="",
                      db="unitTestDB",
                      charset="utf8"
                      )

UPD:

I tested your code against my linux setup (CentOS 6 with MySQL 5.1.73) and I'm not able to reproduce your problem. You may want to try to simplify your credential portion like I did below and see if you still have the issue. Below is what I used to test your stuff and it works fine for me:

# -*- coding: utf-8 -*-

import MySQLdb

for i in range(5):
    print i
    db = MySQLdb.connect(host = "10.100.10.2", user = "root", passwd = "", db = "unitTestDB", charset = "utf8")
    db.close()
0
votes

After googling I find that some times it happen, and reboot can solve problem. I reboot my system and script work correct.