Python 操作 MySQL
本文链接 Python 操作 MySQL 开发环境与配置 win_x64 Ubuntu14.04 Python3.x pip安装pymysql模块 直接使用pip安装 pip install pymysql win64上直接在cmd中执行 连接本地数据库 使用模块 pymysql 连接数据库 本地数据库相关配置请参阅: http://rustfisher.github.io/2017/02/25/backend/MySQL_install/ #!/usr/bin/python # coding=utf-8 import pymysql # 连接本地数据库 conn = pymysql . connect ( host = 'localhost' , port = 3306 , user = 'root' , passwd = 'yourpwd' , db = 'samp_db1' , charset = 'utf8' ) cursor = conn . cursor ( ) cursor . execute ( 'select * from bigstu' ) for row in cursor . fetchall ( ) : print ( row ) # 查 cursor . execute ( 'select id, name from bigstu where age >