是否有方法将python连接到在线数据库?

2024-06-26 19:39:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将我的raspberry pi连接到一个在线数据库并对记录进行更改,但我尝试了服务器时间,它会给我一些错误,如“连接超时”、“根用户使用密码拒绝访问=是”

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")

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


Tags: the数据库sqlconnectorcheck记录mysqlval