Questions tagged [mysql-python]

Use this tag for questions about the MySQL-Python database connector library (MySQLdb). Do not use this tag for questions about MySQL Connector/Python (use the [mysql-connector-python] tag instead).

MySQL-Python, also known as MySQLdb, is a database connector library that implements the Python Database API.

This tag should be used to identify questions related to:

  • Installing the MySQL-Python library;
  • Using the library to connect to a MySQL database from a Python interpreter or script;
  • Specific implementation details of the library; e.g., thread safety, error messages, cursor behavior.

This tag should not be confused with:

The MySQL-Python project is hosted on Sourceforge; however, as of September 2014, a newer package than the one found on Sourceforge (v1.2.4b4) is available from the Python Package Index (v1.2.5).

Andy Dustman (user profile on stackoverflow) has written a detailed User's Guide and maintains a code repository for the project on github.

3186 questions
1896
votes
12 answers

Installing specific package version with pip

I am trying to install version 1.2.2 of MySQL_python, using a fresh virtualenv created with the --no-site-packages option. The current version shown in PyPi is 1.2.3. Is there a way to install the older version? I have tried: pip install…
Joe
  • 25,307
  • 12
  • 38
  • 35
941
votes
24 answers

pip install mysql-python fails with EnvironmentError: mysql_config not found

This is the error I get (mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python Downloading/unpacking mysql-python Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded Running setup.py egg_info for package…
zjm1126
  • 34,604
  • 53
  • 121
  • 166
644
votes
36 answers

mysql_config not found when installing mysqldb python interface

I am trying to get a Python script to run on the linux server I'm connected to via ssh. The script uses mysqldb. I have all the other components I need, but when I try to install mySQLdb via setuptools like so:, python setup.py install I get the…
user904542
  • 6,965
  • 5
  • 20
  • 28
259
votes
18 answers

Replacing Pandas or Numpy Nan with a None to use with MysqlDB

I am trying to write a Pandas dataframe (or can use a numpy array) to a mysql database using MysqlDB . MysqlDB doesn't seem understand 'nan' and my database throws out an error saying nan is not in the field list. I need to find a way to convert the…
FinDev
  • 4,437
  • 6
  • 29
  • 29
178
votes
15 answers

Python mysqldb: Library not loaded: libmysqlclient.18.dylib

I just compiled and installed mysqldb for python 2.7 on my mac os 10.6. I created a simple test file that imports import MySQLdb as mysql Firstly, this command is red underlined and the info tells me "Unresolved import". Then I tried to run the…
toom
  • 5,403
  • 5
  • 24
  • 21
177
votes
9 answers

Visibility of global variables in imported modules

I've run into a bit of a wall importing modules in a Python script. I'll do my best to describe the error, why I run into it, and why I'm tying this particular approach to solve my problem (which I will describe in a second): Let's suppose I have a…
Nubarke
  • 2,020
  • 2
  • 13
  • 12
169
votes
16 answers

ImportError: No module named MySQLdb

I am referring the following tutorial to make a login page for my web application. http://code.tutsplus.com/tutorials/intro-to-flask-signing-in-and-out--net-29982 I am having issue with the database. I am getting an ImportError: No module named…
user3182194
  • 1,729
  • 2
  • 13
  • 9
158
votes
5 answers

What's the difference between MySQLdb, mysqlclient and MySQL connector/Python?

So I've been trying to do some database update with python and while setting up the whole dev environment, I came across these three things which made me dizzy. There's MySQLdb There's mysqlclient And then there's a mysql connector python What's…
आनंद
  • 2,472
  • 4
  • 21
  • 25
115
votes
4 answers

Python MySQLdb: connection.close() VS. cursor.close()

If I use MySQLdb to connect to MySQL-Server through Python. I create a connection and a cursor like this: connection = MySQLdb.connect(...) cursor = connection.cursor() # process When the MySQL-processing is done one should close the connection.…
Aufwind
  • 25,310
  • 38
  • 109
  • 154
114
votes
13 answers

MySQL: Get column name or alias from query

I'm not asking for the SHOW COLUMNS command. I want to create an application that works similarly to heidisql, where you can specify an SQL query and when executed, returns a result set with rows and columns representing your query result. The…
panofish
  • 7,578
  • 13
  • 55
  • 96
97
votes
5 answers

When to close cursors using MySQLdb

I'm building a WSGI web app and I have a MySQL database. I'm using MySQLdb, which provides cursors for executing statements and getting results. What is the standard practice for getting and closing cursors? In particular, how long should my cursors…
jmilloy
  • 7,875
  • 11
  • 53
  • 86
89
votes
10 answers

Print the actual query MySQLdb runs?

I'm looking for a way to debug queries as they are executed and I was wondering if there is a way to have MySQLdb print out the actual query that it runs, after it has finished inserting the parameters and all that? From the documentation, it seems…
xitrium
  • 4,235
  • 4
  • 23
  • 17
77
votes
8 answers

mysql-python install error: Cannot open include file 'config-win.h'

I am trying to run pip install mysql-python connector but it keeps giving me an error "Cannot open include file: 'config-win.h'". The installation works fine on my Mac and another Windows machine, but not this one. I have downloaded Visual Studio…
Chris Meek
  • 1,473
  • 5
  • 20
  • 31
76
votes
6 answers

Python MySQLdb issues (TypeError: %d format: a number is required, not str)

I am trying to do the following insert operation: cursor.execute(""" insert into tree (id,parent_id,level,description,code,start,end) values (%d,%d,%d,%s,%s,%f,%f) """,…
user721975
  • 1,257
  • 3
  • 13
  • 14
75
votes
22 answers

"Cannot open include file: 'config-win.h': No such file or directory" while installing mysql-python

I'm trying to install mysql-python in a virtualenv using pip on windows. At first, I was getting the same error reported here, but the answer there worked for me too. Now I'm getting this following error: _mysql.c(34) : Fatal error C1083: Cannot…
saturdayplace
  • 8,370
  • 8
  • 35
  • 39
1
2 3
99 100