Page 1 of 1

Connect python website with remote SQL Server Database

Posted: Tue Jan 29, 2019 3:40 pm
by ibis777
Hello!

I am creating a website with Python, in a Raspberry Pi 3 B +. I intended to leave it local in the Raspberry, so that when connecting to it the page is displayed. In addition I will also have a MySQL database in the raspberry. However, I also have to connect the website to a SQL Server database, that is hosted on a server. Anyone have any idea about how to connect both with my website? I know that it has something to do with APIs, but I don't even know how to start googling!! :lol:
Thank you!

Re: Connect python website with remote SQL Server Database

Posted: Tue Jan 29, 2019 4:08 pm
by Andyroo
Two and a bit parts here:
1) How to set the sql database up to allow remote connections
2) How to read / write SQL data from Python
bit) Set the firewall up to allow acces (what do you mean you’ve not set it up)

Setting up the database is a case of:
a) Creating a new user (not root) with access to the relevant tables from the remote machine or network
b) Allowing the SQL server to access the network (BIND)

Reading / Writing data
a) Change the connection to the remote server
b) possible look at connection fail / retry / timeout error handling options

Re: Connect python website with remote SQL Server Database

Posted: Fri Feb 01, 2019 3:48 am
by uilfut
You will set up some sort of webserver on your pi (Apache/ nginx/ flask built in). The html (and html generated by python or your framework, eg flask or Django) are your front end.

Your backend will be your mysql database (mariadb on pi) and potentially another external server.

You can connect to these by "load mysql.connector" in python.

This is full stack development so a lot to learn at once but very rewarding.

One pain point is the permissions on the database (you'll know what I mean when you try).

Maybe start with a sqllite database instead locally (so no permissions).

Google full stack web development with flask as a starting point. Good luck!