实现需要有有驱动包 通过包管理下载
mysql.connector
实例代码
#!/usr/bin/env/ python # -*- coding: utf-8 -*- """ @author:Administrator @file: MySql.py @time: 2018/04/04 """ import mysql.connector conn = mysql.connector.connect(user='root',password='root',database='test') cursor = conn.cursor() try: cursor.execute('select * from school') results = cursor.fetchall() for row in results: uuid = row[0] school = row[1] province = row[2] print('uuid :%s ,school:%s , province :%s'%(uuid , school , province)) except Exception as e: print('error: unable to fecth data') finally: cursor.close()
参考链接:
http://www.runoob.com/python/python-mysql.html
https://www.cnblogs.com/hwtmhj/p/6746151.html