# -*- 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()
原文地址:http://blog.csdn.net/weiwei5910/article/details/38922605