在Python中如何连接mysql数据库【面试题详解】

今天爱分享给大家带来在Python中如何连接mysql数据库【面试题详解】,希望能够帮助到大家。

首先,安装mysqldb

然后


#!/usr/bin/python
import MySQLdb

db = MySQLdb.connect(host="localhost", # your host, usually localhost
                     user="john", # your username
                      passwd="megajonhy", # your password
                      db="jonhydb") # name of the data base

# you must create a Cursor object. It will let
#  you execute all the queries you need
cur = db.cursor()

# Use all the SQL you like
cur.execute("SELECT * FROM YOUR_TABLE_NAME")

# print all the first cell of all the rows
for row in cur.fetchall() :
    print row[0]

原文链接:http://blog.itblood.com/4540.html,转载请注明出处。
0
破碎的心灵v0.21赞助修复 AI版[PC+安卓/7.49G/更新]Shattered Minds [v0.21] [欧美SLG/汉化/动态]
破碎的心灵v0.21赞助修复 AI版[PC+安卓/7.49G/更新]Shattered Minds [v0.21] [欧美SLG/汉化/动态]
3分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?