Connection with closing mysqldb error for Python

I had a problem closing the connection as follows:

database = 'sed_database' conn = MySQLdb.Connect(host='remote_host', user='default', passwd='pass', db=database) try: try: cursor = conn.cursor() cursor.execute(sql_str) results = cursor.fetchall() except MySQLdb.Error, e: print "MySQL/Server Error using query: %s" % sql_str print "Using database: %s" % database raise e finally: if cursor: cursor.close() if conn: conn.close() 

This gives:

  Traceback (most recent call last): File "trass.py", line 579, in ? main(sys.argv) File "trass.py", line 555, in main old_rows, changes_list = auto_analyse_test(f, args.build, args.quiet, args.debug) File "trass.py", line 352, in auto_analyse_test last_analysed_build = get_sed_baseline_ref(test_file_name, old_delivery_stream) File "trass.py", line 151, in get_sed_baseline_ref results = execute_sql_query(sql, delivery_stream) File "trass.py", line 197, in execute_sql_query passwd='pass', db=database) File "C:\Python24\Lib\site-packages\MySQLdb\__init__.py", line 75, in Connect return Connection(*args, **kwargs) File "C:\Python24\Lib\site-packages\MySQLdb\connections.py", line 164, in __init__ super(Connection, self).__init__(*args, **kwargs2) _mysql_exceptions.InternalError: (3, "Error writing file 'D:\\MySQL_Datafiles\\Logfiles\\query. log' (Errcode: 9)") 

The Python MySQLDB library information is as follows:

 >>> print MySQLdb.get_client_info() 4.1.18 >>> print MySQLdb.__version__ 1.2.1_p2 >>> print MySQLdb.__revision__ 410 

It is strange that:

  • I checked the server and query.log exists and is being written by other processes.
  • This code works through several iterations, and then it fails on a specific element.
  • An exact query is performed using SQLyog and yields four results.

The error.log server says: "The connection was lost ... (Received error message reading messages)"

While the Traceback message appears indicating that the error was due to the creation of the connection, this does not happen until the connection is closed (or the termination of the function, which I assume closes it by default). I tried to put extra output or pauses between opening and closing. Every time an exception occurs at close. So what can cause this error when closing the connection?

+8
python mysql mysql-python
source share
1 answer

Here is what I have found so far.

It seems that the error occurs when opening the connection, with MySQLdb.Connect(...) , the 2nd row in the inserted code, and not when closing the connection.

Full back trace:

  • ...
  • execute_sql_query [op]
  • MySQLdb Connect [op]
  • MySQLdb super (...) [op]
  • _mysql.c ConnectionObject_Initialize [lower level pyhon module written in C]
  • libmysql mysql_real_connect or mysql_options [possibly earlier]
  • failure, exception set

Let decode exception

 InternalError: (3, "Error writing file 'D:\\MySQL_Datafiles\\Logfiles\\query.log' (Errcode: 9)") 
  • "3" old mysql mysys_err.h EE_WRITE 3
  • Is "query.log" a local or remote log file? looks like a path to the window.
  • "Error code: 9", assuming windows (above), that is, ERROR_INVALID_BLOCK "Invalid storage control unit address". Quite cryptic, but it will go and check if this file exists, if it is writable, and if it may be subject to logrotate or the like. Check the disk space, for a good measure, check the disk.

This seems to be a client-side error. Check the my.cnf , [client] section on the client side.

source code for this version of MySQLdb

+3
source share

All Articles