Forums

access python anywhere my SQL externally from local machine

Hi, I am new to python anywhere. I created my first app with flask and it is working cool.

I am trying to connect SQL database with in my app and externally from local server.

in python anywhere server it is working fine, if I try the same from my local machine. it is not working. can you guide me, how to achieve this.

I used following code:

import MySQLdb
username = 'xxxx'
password = 'yyyy'
hostname = 'xxxx.mysql.pythonanywhere-services.com'
db = 'xxxx$default'

conn = MySQLdb.connect(host=hostname, user=username, passwd=password, db=db)
cursor = conn.cursor()

cursor.execute('SELECT * from table1')
row = cursor.fetchone()
print(row)
conn.close()

See https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere/ and note that that will not work on a free account.

Thank you glenn. this helps a lot.