Forums

Mysql connection problem from raspberry pi

Hi, My database is at:

forsterc.mysql.pythonanywhere-services.com

Username: forsterc Your databases: forsterc$dblight

My code:

import MySQLdb

db = MySQLdb.connect(
    host = "forsterc.mysql.pythonanywhere-services.com",
    user = "forsterc",
    passwd = "*********",
    db = "forsterc$dblight"
    )

cursor = db.cursor()

cursor.execute("SELECT * FROM tbllight")

for x in cursor:
    print(x)

cursor.close()
db.close()

Can't connect to server on 'forsterc.mysql.pythonanywhere-services.com' (10060)

Not sure why!

Where are you running this code? If you want to connect with your PythonAnywhere db from outside, you need a paid account (see this help page as well). Otherwise, check this help page.