


PLC / 温度变送器
↓ Modbus
Python 数据采集
↓
MySQL 数据库存储




mysql -u root -p


pip install pymysql //安装pymysql依赖
pymysql.connect() | ||
db.cursor() | ||
cursor.execute() | ||
db.commit() | ||
cursor.fetchall() | ||
cursor.fetchone() | ||
db.close() | ||
cursor.close() | ||
CREATE DATABASE | ||
CREATE TABLE | ||
INSERT INTO | ||
SELECT | ||
UPDATE | ||
DELETE |




# MySQL连接db = pymysql.connect(host="localhost",user="root",password="密码",database="公众号小狗儿饼干" #数据库名)cursor = db.cursor()# 写入数据库sql = "INSERT INTO `device_log` (temperature, humidity, status, time) VALUES(%s, %s, %s, %s)"cursor.execute(sql, (temperature, humidity, status, now))db.commit()print("写入成功:", now)
