Installation of Pthon MySQLdb

Source: Internet
Author: User

Description

To use Python to connect to MySQL we need a driver this program is Mysql-python, so we first want to the next corresponding version of the Mysql-python (note that this driver only 32-bit version, so your Python The environment is best if 32 people)

0th step: Download the 32-bit Python and install: http://yunpan.cn/cQQnKwfeIRHq7 access password Def6

First step: Download MySQLdb and install: http://yunpan.cn/cQQtnsLcsGyEr access password 6038

If you finish the above two steps, the environment will be there, we can write the program below.

Example one:

Import MySQLdb #首先要import This package

conn = MySQLdb.connect (host= ' 127.0.0.1 ', user= ' root ', passwd= ' 131417 ', db= ' Studio '); #定义一个连接对象

cursor = Conn.cursor (); #得到返回的cursor对象.
Cursor.execute (' select * from T '); #执行语句

for (x, y) in cursor: #取结果集
print ' x is%s y is%s '% (x, y);

Cursor.close (); #这两个都要close to disconnect
Conn.close ();

Installation of Pthon MySQLdb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.