Python MySql 数据库操作
来源:程序员人生 发布时间:2014-10-12 18:59:39 阅读次数:2819次
# -*- coding: utf-8 -*-
# mysqlTest.py
import mysql.connector
conn = mysql.connector.connect(user='root',host='127.0.0.1', port='3306', password='admin', database='test_db', use_unicode=True)
cursor = conn.cursor()
# cursor.execute('insert into table_test(id, name) values(%s, %s)', ['4', 'hello wangwei'])
# cursor.rowcount
# conn.commit()
# cursor.close()
cursor = conn.cursor()
cursor.execute('select * from table_test')
values = cursor.fetchall()
print values
cursor.close()
conn.close()
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠