python - 有没有将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")
我想要的输出是我可以将记录插入远程数据库。
解决方案
推荐阅读
- javascript - 当第一个元素的 aria-hidden 处于活动状态时,有条件地渲染第二个元素
- mysql - 从 MySQL 5.7 获取单个用户排名位置
- false-positive - 我是新手,不知道该怎么做
- r - .local(x, p, ...) 中的错误:超过一半的存在点具有 NA 预测值
- android - 如何在jetpack compose中获取带有外部活动的视图模型
- java - 放心 - JSON 模式验证 - java.lang.NoSuchMethodError: com.github.fge.jsonschema.core.processing.CachingProcessor
- forms - 表单颤振中的公开下拉菜单
- android - 如何绕过网页的用户代理检查器并在 chrome 中打开它?
- python - 删除特定字符之后的所有字符,而不是字符本身,在整列中,python
- reactjs - useLocation 和 useParams 会返回未定义的初始值吗?