首页 > 解决方案 > 有没有将python连接到在线数据库的方法?

问题描述

我想将我的树莓派连接到在线数据库并更改记录,但我尝试了几次它给我的错误,例如“连接超时”,“使用密码=是的root用户访问被拒绝”

import mysql.connector 

mydb = mysql.connector.connect(
  host="sql106.epizy.com",
  user="epiz_24910878",
  passwd="jianliang176",
  database="epiz_24910878_mydb"

)
mycursor = mydb.cursor()


def insertStudentCheckin():
    try:

        sql = "INSERT INTO tblUser (uName,uPW) VALUES (%s,%s)"
        val = (str(2),'absent')
        #insert the check in with card id and today time and date
        #first time is insert so no nid to check the card id value
        mycursor.execute(sql, val)

        mydb.commit()

        print(mycursor.rowcount, "student today record inserted.")
    except Exception as e:
        print(e)
print("hello")
insertStudentCheckin()
print("world")

我想要的输出是我可以将记录插入远程数据库。

标签: pythonmysqlraspberry-pi

解决方案


推荐阅读