通过MySQLdb
#!/usr/bin/python
import MySQLdb
db = MySQLdb.connect(
host="dsql.aliyuncs.com", # 主机名
port=3306, # 端口号
user="your-dsql-account", # DSQL账号
passwd="your-password") # DSQL密码
cur = db.cursor()
cur.execute("select * from testlink.testdb.testtb where id = 1")
for row in cur.fetchall():
print(row[0])
db.close()
通过PyMySQL
import pymysql
conn = pymysql.connect(host='dsql.aliyuncs.com',port='3306', user='your-dsql-account', passwd='your-password')
cur = conn.cursor()
cur.execute("SELECT * from testlink.testdb.testtb where id = 1")
for r in cur:
print(r)
cur.close()
conn.close()
反馈
- 本页导读 (1)
文档反馈