Posts: 35
Joined: Tue Mar 28, 2017 6:03 am

How do I connect to my MySQL on my website DB?

Thu Jun 28, 2018 4:20 am

I have a sensor that is printing data. I need to have that data sent to my database on my website. None of the tutorials work. How do I connect my RPI to my Dbase?

I am not a programmer and have very little knowledge of coding in python. It would be great if someone code write the code, tell me where it goes on my code and what info I need to complete to make it work.

Posts: 2
Joined: Sat Jun 30, 2018 5:01 pm

Re: How do I connect to my MySQL on my website DB?

Sat Jun 30, 2018 5:26 pm

You can setup MySQL to allow remote logins. This has to be configured server side. There's an example here: ... erver.html

After configuring MySQL remote access, you can do something like this:

Code: Select all

DB = 'gts'
DB_HOST = ''
DB_USER = 'root'
DB_PASSWORD = 'dbadminpassword'
conn = MySQLdb.Connection(db=DB, host=DB_HOST, user=DB_USER,passwd=DB_PASSWORD)
cursor = conn.cursor()

User avatar
The Traveler
Posts: 363
Joined: Sat Oct 21, 2017 3:48 pm

Re: How do I connect to my MySQL on my website DB?

Mon Jul 02, 2018 1:38 pm

Where is your db located? Commercial server? Institutional, ie: school? Private? Being able to access your mySQL db usually requires some intervention on the part of the system administrator. There is a wide range of options for access and you'll need to know the particulars. It's hard to make recommendations otherwise.

Retired IT professional, C programmer and "beardie weirdie".
RPi interests: Developing an Infinite Improbability Drive
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

User avatar
Posts: 38798
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How do I connect to my MySQL on my website DB?

Mon Jul 02, 2018 1:42 pm

If your database server isn't on your local LAN then you really want to run port 3306 traffic through a TLS secure tunnel. ... tions.html
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Python”