当前位置:Gxlcms > 数据库问题 > python 简单连接mysql数据库

python 简单连接mysql数据库

时间:2021-07-01 10:21:17 帮助过:10人阅读

!/usr/bin/python # encoding: utf-8 """ @version: v1.0 @author: dabao @license: Apache Licence @contact: robbile@163.com @site: http://www.cnblogs.com/EWWE/ @software: PyCharm Community Edition @file: 1225.2.mysql.py @time: 2017/12/25 22:07 """ import pymysql try: db = pymysql.connect("127.0.0.1", "root", "123456") cursor = db.cursor()#数据游标 cursor.execute("show databases")#查询所有数据库 cursor.execute("use world")#使用world数据库 cursor.execute("show tables")#查询所有表 cursor.execute("show columns from city")#查询表信息 cursor.execute("select * from city where id<10")#查询city表中ID小于10的数据 date = cursor.fetchall()#查询结果 print date#打印查询结果 db.close() print "登陆成功" except: print "登陆失败"

 

python 简单连接mysql数据库

标签:databases   cut   class   nec   安装   pychar   mmu   time   登陆   

人气教程排行