Answer the question
In order to leave comments, you need to log in
How to connect to a database on another server?
Hello!
Guys, I use raspberry pi, it collects data from the sensor from me.
There is also an ubuntu on which the site is configured (locally) and there is a database.
I want to send data from raspberry to the ubuntu database, I do it all in python.
But first I want to at least connect to the database by installing:
sudo apt-get install python-mysqldb
I do this:
#!/usr/bin/python
import MySQLdb
# подключаемся к базе данных (не забываем указать кодировку, а то в базу запишутся иероглифы)
db = MySQLdb.connect(host="192.168.1.8", user="root", passwd="root", db="contacts", charset='utf8')
# формируем курсор, с помощью которого можно исполнять SQL-запросы
cursor = db.cursor()
# закрываем соединение с базой данных
db.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question