112
votes
7answers
36k views

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 ...
231
votes
19answers
109k views

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 ...
97
votes
18answers
66k views

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 ...
186
votes
2answers
85k views

Installing specific package versions with Pip

I'm trying to install version 1.2.2 of the MySQL_python adaptor. The current version shown in PyPi is 1.2.3. Is there a way to install the older version? I found an article stating that this should do ...
2
votes
2answers
3k views

How to insert pandas dataframe via mysqldb into database?

I can connect to my local mysql database from python, and I can create, select from, and insert individual rows. My question is: can I directly instruct mysqldb to take an entire dataframe and insert ...
5
votes
4answers
12k views

Installing MySQLdb on Mac OS X

I've spent several hours trying to install MySQLdb (the Python library) on Mac OS X Snow Leopard. I'm using these instructions from SO. I keep getting an error, so I've tried using MacPorts (as one of ...
9
votes
2answers
8k views

cc1: error: unrecognized command line option “-Wno-null-conversion” within installing python-mysql on mac 10.7.5

This error broke my python-mysql installation on Mac 10.7.5. Here are the steps The installed python is 2.7.1, mysql is 64 bit for 5.6.11. The being installed python-mysql is 1.2.4, also tried ...
23
votes
5answers
7k views

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 ...
17
votes
12answers
14k views

mysql-python install problem using virtualenv, windows, pip

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 ...
6
votes
2answers
10k views

Python - Visibility of global variables from 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 ...
7
votes
3answers
3k views

What's the most efficient way to convert a MySQL result set to a NumPy array?

I'm using MySQLdb and Python. I have some basic queries such as this: c=db.cursor() c.execute("SELECT id, rating from video") results = c.fetchall() I need "results" to be a NumPy array, and I'm ...
1
vote
3answers
4k views

Trouble Setting Up MySQLdb Module

I'm pulling my hair out over here trying to set up MySQLdb on my Mac in order to connect to a remote MySQL server. I have installed the latest C MySQL client libraries I have installed XCode 4 I ...
9
votes
2answers
21k views

Python MYSQL update statement

I'm trying to get this Python MYSQL update statement correct(With Variables): cursor.execute ("UPDATE tblTableName SET Year=%s" % Year ", Month=%s" % Month ", Day=%s" % Day ", Hour=%s" % Hour ", ...
6
votes
3answers
4k views

Python MySQLdb returns datetime.time and decimal

I have a MySQL queries SELECT mydate, countryCode, qtySold from sales order mydate, countryCode This returns tuples of tuples with values like [[datetime.date(2011, 1, 3), 'PR', Decimal('1')], ...
3
votes
1answer
852 views

Python MySQLdb execute table variable

I'm trying to use a variable for a table name. I get the error "... near ''myTable'' at line 1 I must not be escaping this right. The double '' in the error seems to be a clue, but I don't get it. db ...
12
votes
2answers
5k views

Can't install python mysql library on Mac Mavericks

It was working like a charm before the update from Mountain Lion. After the update it is broken and I cannot get the environment up again. Does anybody know how to fix this? The error is bolded, ...
9
votes
2answers
6k views

/usr/bin/ld: cannot find -lpython2.7

I'm trying to install MySQLdb with Python 2.7. The error I'm getting looks like this: gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC ...
4
votes
3answers
1k views

how to insert to a mysql table using mysaldb, where the table name is in a python variable?

I'm using python-mysql db api to insert some values to a table where the table name is in a python variable. So I wrote the below code DB_CURSOR.execute("""INSERT INTO %s ...
1
vote
2answers
3k views

Python 3.4.0 with MySQL database

I have installed Python version 3.4.0 and I would like to do a project with MySQL database. I downloaded and tried installing MySQLdb, but it wasn't successful for this version of Python. Any ...
1
vote
2answers
4k views

How to setup up PYTHON_EGG_CACHE environment variable on Mac?

I am trying to setup Django to use MySQL. I am getting the following error when I type in localhost/mysite ExtractionError at / Can't extract file(s) to egg cache The following error occurred while ...
1
vote
2answers
312 views

Is there any safe way to parameterize database names in MySQL queries?

I'm writing a little python script to help me automate the creation of mysql databases and associated accounts for my personal projects. Part of this script is a function that takes the database name ...
-1
votes
2answers
5k views

About MySQLdb conn.autocommit(True)

I have installed python 2.7 64bit,MySQL-python-1.2.3.win-amd64-py2.7.exe. I use the following code to insert data : class postcon: def POST(self): ...
3
votes
3answers
3k views

How do I check if an insert was successful with MySQLdb in Python?

I have this code: cursor = conn.cursor() cursor.execute(("insert into new_files (videos_id, filename, " "is_processing) values (%s,%s,1)"), (id, filename)) logging.warn("%d", ...
2
votes
1answer
4k views

Python: ValueError: unsupported format character ''' (0x27) at index 1

I'm trying to execute a query to search 3 tables in a database using MySQL through Python. Every time I try and execute the following string as a query, it gives me an error about concatenation in the ...
2
votes
4answers
606 views

Python and MySQLdb: substitution of table resulting in syntax error

I need to dynamically change tables and variables from time to time, so I wrote a python method like this: selectQ ="""SELECT * FROM %s WHERE %s = %s;""" ...
2
votes
1answer
3k views

Python / MySQL (MySQLdb) - testing the 'insert' function - its not adding rows. Why?

I'm trying to figure out how to use the MySQLdb library in python (I am novice at best for both of them). I'm following the code here: http://www.kitebird.com/articles/pydbapi.html Specifically: ...
1
vote
3answers
2k views

Mac OSX : python packages failed to build because of gcc issues

I am trying to install MySQL-python package with the following error: cc1: error: unrecognized command line option "-arch" cc1: error: unrecognized command line option "-Wno-long-double" error: ...
0
votes
1answer
53 views

how to add a new column every time i run a python program

i want my table to have 1st column as roll no,second as name.whenever i run python program i want to add a column of date in table.and in that new column i want to populate the list which i get from ...
21
votes
4answers
8k views

Python MySQLdb: When to close cursors

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 ...
15
votes
3answers
18k views

error: Setup script exited with error: command 'gcc' failed with exit status 1

I get the following error when I try to install MySQL-python-1.2.3 under Python 2.6 in Fedora 14. Fedora 14 comes with Python 2.7 by default and I am working in a project which runs in Python 2.6, ...
12
votes
2answers
7k views

Using PIP in a virtual environment, how do I install MySQL-python

When I'm in my virtual environment, I attempt to run: pip install MySQL-python This didn't work, so I tried downloading the package and installing it by running: python setup.py install This ...
9
votes
2answers
8k views

Installing MySQL-python on mac

I am using OSX 10.8 and PyCharm to work on a Python development project. I have installed MySQL-python for the mac using the instructions on the website ...
6
votes
1answer
2k views

Have MySQLdb installed, works outside of virtualenv but inside it doesn't exist. How to resolve?

I'm using the most recent versions of all software (Django, Python, virtualenv, MySQLdb) and I can't get this to work. When I run "import MySQLdb" in the python prompt from outside of the virtualenv, ...
4
votes
1answer
694 views

How to store real-time chat messages in database?

I am using mysqldb for my database currently, and I need to integrate a messaging feature that is in real-time. The chat demo that Tornado provides does not implement a database, (whereas the blog ...
20
votes
2answers
7k views

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 ...
4
votes
4answers
4k views

How to check if record exists with Python MySQdb

Im creating a python program that connects to mysql. i need to check if a table contains the number 1 to show that it has connected successfully, this is my code thus far: xcnx.execute('CREATE TABLE ...
2
votes
1answer
13k views

python setuptools installation in centos

i have to install mysqldb module of python in my centos server. i have 2 versions of python 2.4.3 the default one 2.6 which i installed i want to install mysqldb module for 2.6 version of the ...
1
vote
1answer
1k views

Twisted, MySQLdb and (2006, 'MySQL server has gone away') using Twisted adbapi

In twisted I am a perpetual event loop that is always lookig for a new query to run It polls a SQS queue and are are times where time between queres is long enough to time out and this is the error I ...
0
votes
1answer
1k views

Moving large SQL query to NumPy

I have a very large MySQL query in my web app that looks like this: query = SELECT video_tag.video_id, (sum(user_rating.rating) * video.rating_norm) as score FROM video_tag JOIN user_rating ON ...
5
votes
1answer
6k views

ImportError: No module named mysql.base, in django project on Ubuntu 11.04 server

I am following the steps in the Django Book and got to the part where the authors explain hot wo set up a django project to use a database. I chose mysql. My settings in settings.py are: DATABASES = ...
5
votes
2answers
2k views

MySQLdb is extremely slow with large result sets

I executed the following query both in phpMyAdmin & MySQLdb (python). SELECT *, (SELECT CONCAT(`id`, '|', `name`, '|', `image_code`) FROM `model_artist` WHERE `id` = `artist_id`) as artist_data, ...
4
votes
2answers
1k views

Python MySQLdb converters isn't working

I'm trying to run an ETL script using python and MySQLdb but I'm stuck with the results from my initial extract query. The types returned are all Long and Decimal when I want Int and Float. I've ...
4
votes
1answer
4k views

MySQL-python, error: command 'gcc-4.2' failed with exit status 1

I've been looking around for a solution to this, and there seem to be a lot of different solutions, but none seem to be working. I'm using MySQL-Python to try to get MySQL set up with python. But, ...
4
votes
2answers
3k views

python easy_install: specify directory housing required files

I'm trying to use easy_install to install MySQL-python. It fails almost immediately: _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file ...
3
votes
2answers
41 views

MySQLdb is caching SELECT results?

i'm running a SELECT query in a loop. Once in a while, the database table is updated (by another program). The first SELECT retrieves the correct data, but further calls in the loop return the first ...
3
votes
2answers
850 views

Reconnecting MySQL on timeout

I have a Python program which runs on background for weeks, and does database queries every once in a while. For that, I am using the ORM peewee (version 2.2.1). I am using MySQL as a backend. Lately ...
2
votes
1answer
403 views

Is __enter__ and __exit__ behaviour for connection objects specified in the Python database API?

Background I recently discovered the Python with keyword and started seeing its potential usefulness for more prettily handling some scenarios where I'd previously have used try: ... finally: ... ...
0
votes
0answers
186 views

Can't connect to MySQL server on %s? - MySQLdb

I'm trying to connect to my internet server using python. To connect'm using MySQLdb library. The problem is that I can not connect with Python, but if using other programs, such as MySQL Workbench, ...
7
votes
1answer
2k views

python mysqldb multiple cursors for one connection

When you have one connection object, can you make multiple cursors to that one single connection and execute queries with these cursors at the same time? Or would each cursor wait for the previous ...
4
votes
1answer
916 views

Can I use with statement with MySQLdb.Connection object?

I wonder if I can use the context manager with with the Connection object, and write code like this: with MySQLdb.connect(...) as conn: do_something() Will the conn object be closed ...