I have setup a private home server using my raspberry pi 3. It has MySQL as its database. It hosts my personal website and i want to access its MySQL database remotely using python. It works perfectly fine when the database is hosted on shared hosting like GoDaddy. The main reason I'm unable to connect to the server is because my server doesn't has a static IP. I made its IP static using NoIP.
The web URL to my hosted website ends with ddns.net
This is my python code using which I,m trying to connect to the remote mysql server
import pymysql as _sql
SQL = None
def SQL_ONLINE_CONNECTION():
try:
connection = _sql.connect(host='URL',
user='USERNAME',
password='PASSWORD',
db='DBNAME',
charset='utf8mb4',
port=3306,
cursorclass=_sql.cursors.DictCursor)
return connection
except _sql.err.OperationalError as e:
return False
def Boot():
global SQL
try:
SQL = SQL_ONLINE_CONNECTION()
if SQL is not None:
print("[MYSQL CONNECTION ESTABLISHED!]")
else:
print("[FAILED!]")
except Exception as e:
print(e)
if __name__ == '__main__':
Boot()
I cannot even ping to my raspberry server using its URL address.
**Please ignore my python code styling as i had to copy every line here and put 4 spaces to display them as code.