开发者社区> 问答> 正文

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

我想把我的树莓派连接到一个在线数据库,并作出改变的记录,但我尝试了几个时间,它给我的错误,如“连接超时”,“拒绝访问根用户使用密码= yes”

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

我想要的输出是可以将记录插入远程数据库。 问题来源StackOverflow 地址:/questions/59386448/is-there-method-to-connect-python-to-online-database

展开
收起
kun坤 2019-12-25 21:58:42 701 0
1 条回答
写回答
取消 提交回答
  • 这应该是服务器权限的问题,建议设置用户与密码开放数据库权限

    2020-03-25 17:17:58
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载