Mysqldb connection problem

A forum for general discussion of the Python programming language.

Mysqldb connection problem

Postby zainuddin » Mon Aug 26, 2013 5:40 am

i already installed mysql-python, but having problem like this
Code: Select all
import MySQLdb

db = MySQLdb.connect(host="localhost", user="root", passwd="1234567", db="test")

cur = db.cursor()

#execute an sql query
cur.execute("SELECT firstname,lastname FROM")

for row in cur.fetchall() :
      #data from rows
        firstname = str(row[0])
        lastname = str(row[1])

        print "This Person's name is " + firstname + " " + lastname

# close the cursor

# close the connection
db.close ()


Code: Select all
Zainuddin-MacBook-Pro:python zainuddin$ python
Traceback (most recent call last):
  File "", line 4, in <module>
    db = MySQLdb.connect(host="localhost", user="root", passwd="1234567", db="test")
  File "/Library/Python/2.7/site-packages/MySQLdb/", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/MySQLdb/", line 147, in __init__
    from MySQLdb.converters import conversions
  File "/Library/Python/2.7/site-packages/MySQLdb/", line 54, in <module>
    ArrayType = array.array
AttributeError: 'module' object has no attribute 'array'

please help me, i need your advise. tq
Posts: 1
Joined: Mon Aug 26, 2013 5:38 am

Re: Mysqldb connection problem

Postby stranac » Mon Aug 26, 2013 7:07 am

There is one pretty common way errors like this happen.
Do you have a file named '' or 'array.pyc' in the directory you're executing this from?
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

Return to General Discussions

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests