Search code examples
pythonattributesexecute

Python MySQL AttributeError: 'function' object has no attribute 'execute'


I am trying to retrieve data from tables in MySQL on Python. But I have received

AttributeError: 'function' object has no attribute 'execute'

My code is:

import mysql.connector as sqltor
mycon=sqltor.connect(host="localhost",user="root",passwd=" ",database="revision")
if mycon.is_connected():
    print("Successfully Connected to MySQL database.")
else:
    print("Check yo inputs, they really correct?")

cursor=mycon.cursor
cursor.execute("select*from account")

Output:

Successfully Connected to MySQL database.
Traceback (most recent call last):
  File "C:/Users/biina/Documents/Python/Apparel store/Python/Practical File/Interface_Python_with_MySQL.py", line 10, in <module>
    cursor.execute("select*from account")
AttributeError: 'function' object has no attribute 'execute'

Solution

  • You need to call the cursor function. So replace cursor=mycon.cursor with cursor=mycon.cursor()