import pymysql
connc = pymysql.connect(
host='127.0.0.1',
user='root',
password='020804',
database='person',
port=3305,
charset='utf8'
)
cur = connc.cursor()
sql = 'select * from info;'
cur.execute(sql)
result = cur.fetchall()
print(result)
connc.close()
import pymysql
try:
connc = pymysql.connect(
host='127.0.0.1',
user='root',
password='020804',
database='person',
port=3305,
charset='utf8'
)
cur = connc.cursor()
sql = 'select * from info;'
cur.execute(sql)
result = cur.fetchall()
print(result)
cur.close()
connc.close()
except Exception as e:
print(e)
————————————————————————————————————————————————————————————————————————————————————
eg:
import pymysql
try:
connc = pymysql.connect(
host='127.0.0.1',
user='root',
password='020804',
database='persons',
port=3305,
charset='utf8'
)
cur = connc.cursor()
sql = 'select * from info;'
cur.execute(sql)
result = cur.fetchall()
print(result)
cur.close()
connc.close()
except Exception as e:
print(e)
在这里插入代码片