标签:%s har span chm fetchone host api char pytho
先安装 pip python 的包管理工具
然后
sudo pip install mysql-connector-python
连接数据库
#!/usr/bin/python # -*- coding: UTF-8 -*- import mysql.connector db = mysql.connector.connect( host = ‘127.0.0.1‘, port = 3306, user = ‘root‘, passwd = ‘gou110422‘, database = ‘test‘, charset = ‘utf8‘ ) cursor = db.cursor() sql_query = ‘select name,money from user;‘ #执行sql 语句 cursor.execute(sql_query) print cursor.rowcount rs = cursor.fetchall() #cursor.rowcount 表中受影响数据个数 #fetchall() 获取所有数据 #fetchone() 获取一条数据 #fetchmany(3) 获取 3个数据 print rs for item in rs: print ‘name: %s money: %s‘ % item print ‘成功‘ #cursor.close() #关闭游标 db.close()
api:http://www.runoob.com/python3/python-mysql-connector.html
python操作mysql——mysql.connector
标签:%s har span chm fetchone host api char pytho
原文地址:https://www.cnblogs.com/bruce-gou/p/10218435.html