1

I want to simply access the database of mysql through python.But when I am running this code :

import MySQLdb
db = MySQLdb.connect(host = "127.0.0.1",
                     port = "3306",
                      user="Bishnu",
                      passwd = "Pulchowk",
                      db = "student")
cursor =db.cursor()
cursor.execute("select * from basic_info")
numrows = int(cursor.rowcount)
for x in range(0,numrows):
    row = cursor.fetchall()
    print row[0],"-->",row[1]
db.cose()

It gives an error as :

Traceback (most recent call last):
  File "C:\Users\Bishnu\Desktop\database", line 6, in <module>
    db = "student")
  File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required

What is that TypeError : an integer is required

Why such problem occurs? To run this code I have got 3 problems but luckily this forum solved my two problems, I think it will also be solved ?

2
  • it may not be able to connect to the mysql server. Make sure its running. Commented Jan 25, 2013 at 7:35
  • I am sure that Mysql server is running, but it still shows the same problem. But my friend also have tried it but he has no problem. Any ohter idea about it ? Commented Jan 30, 2013 at 10:00

1 Answer 1

16
db = MySQLdb.connect(host = "127.0.0.1",
                 port = "3306",
                  user="Bishnu",
                  passwd = "Pulchowk",
                  db = "student")

try replacing:

port = "3306"

with

port = 3306

(remove the quotes)

Sign up to request clarification or add additional context in comments.

3 Comments

I have tried but shows the error OperationalError: (1045, "Access denied for user 'Bishnu'@'localhost' (using password: YES)")
That means the IntegerType error is solved, however now it's a credential problem. double-check your credentials to log into mysql, perhaps double check via command-line.
furthermore - it's in your best interest to REMOVE any passwords before posting on public boards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.