本文通过python 3 的pymysql模块进行mysql数据库的连接以及数据操作
#!/usr/bin/python3.51/
# -*- coding: utf-8 -*-
import pymysql
conn = pymysql.connect(host='111.111.111.111',
port=3306,
user='root',
password='1234') #输入数据库的账号密码
print('连接数据库OK!')
conn.select_db('test') #db:选择要连接的库名
cur = conn.cursor() #创建游标
cur.execute('select * from a ') #查询
data=cur.fetchall() #获取查出的数据
print('输出数据:')
for d in data:
print(d)
conn.close() #关闭与数据库的连接
运行结果: