MySQLdb returns "ValueError: invalid literal for float():" for cursor.execute('show databases')

Tim Williams timothy.williams at nvl.army.mil
Fri May 28 08:48:31 EDT 2004


wes weston <wweston at att.net> wrote in message news:<IIutc.1453$_k3.28756 at bgtnsc05-news.ops.worldnet.att.net>...
> Tim Williams wrote:
> > I'm trying to write a simple python program to access a MySQL
> > database. I'm having a problem with using MySQLdb to get the results
> > of a SQL command in a cursor. Sometimes the cursor.execute works,
> > sometimes not.

(snip)

> 
> Tim,
>     I tried this code and, as you can see, it worked:
> 
> import MySQLdb
> 
> db = MySQLdb.connect(user="wes", passwd="?????",db="PortfolioMySql",port=3306,unix_socket="/tmp/mysql.sock")
> cursor= db.cursor()
> sql = "show databases"
> cursor.execute(sql)
> while 1:
>      t = cursor.fetchone()
>      if not t:
>          break
>      print t
> cursor.close()
> db.close()
> 
>  >>>
> ('PortfolioMySql',)
> ('mysql',)
> ('test',)
>  >>>
> 
> wes

I think I found the problem. I installed mysql and MySQLdb in
non-standard places so I wouldn't need root access. (I'm not an
admin.) It turns out that the  switch --enable-thread-safe-client is
*not* used by default in the mysql install, but the default for
MySQLdb is to assume that it is used. What was happening was that
MySQL db was loading in /usr/lib/mysql/libmysqlclient_r.so.10 since my
install dir for mysql didn't have that library built.

If I change the MySQL setup.py to 

# set this to YES if you have the thread-safe mysqlclient library
thread_safe_library = NO

and reinstall it, things work.

I'm working on building my version of mysql with
--enable-thread-safe-client and  MySQLdb with thread_safe_library =
YES to see if this works too. I expect so.



More information about the Python-list mailing list