Page 1 of 1

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

Posted: Thu Jun 28, 2018 4:20 am
by ghostrider513
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.

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

Posted: Sat Jun 30, 2018 5:26 pm
by raspcoder
You can setup MySQL to allow remote logins. This has to be configured server side. There's an example here: https://www.cyberciti.biz/tips/how-do-i ... erver.html

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

Code: Select all

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

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

Posted: Mon Jul 02, 2018 1:38 pm
by The Traveler
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.

Cheers.

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

Posted: Mon Jul 02, 2018 1:42 pm
by DougieLawson
If your database server isn't on your local LAN then you really want to run port 3306 traffic through a TLS secure tunnel.

https://dev.mysql.com/doc/refman/8.0/en ... tions.html