Python module ' mysqldb '

Source: Internet
Author: User

1. Import MySQL Module

Python 2.7.5 (Default, June, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on Linux2type "help", "copyright", " Credits "or" license "for more information.>>> import Mysqldbtraceback (most recent call last): File" <stdin& gt; ", line 1, in <module>importerror:no module named mysqldb>>>

Installing the MySQL module

[[email protected] ~]# wget  https://pypi.python.org/packages/source/m/mysql-python/mysql-python-1.2.5.zip[[email protected] ~]#  unzip MySQL-python-1.2.5.zip[[email protected] MySQL-python-1.2.5]# python  setup.py build[[email protected] mysql-python-1.2.5]# python setup.py install#   or so (centos/redhat) [[email protected] ~]# yum install mysql-python         #  pre-configured Yum source #  re-import successfully [[email protected] ~]#  pythonpython 2.7.5  (default, jun 24 2015, 00:41:19)  [GCC 4.8.3  20140911  (red hat 4.8.3-9)] on linux2type  "Help",  "copyright",  " Credits " or " license " for more information.>>> import mysqldb 

2, the use of MYSQLDB module

Import Mysqldbconn = MySQLdb.connect (host,user,passwd,dbname,port) cur = conn.cursor () cur.execute (' SELECT * FROM Mysql.user where user= "Shaw") print Cur.fetchone () # printout Cur.close () Conn.close ()
Import Mysqldbtry:conn = MySQLdb.connect (host,user,passwd,dbname,port) cur = conn.cursor () cur.execute (' SELECT * From Mysql.user where user= "Shaw" ') print Cur.fetchone () # printout cur.close () Conn.clos E () except Mysqldb.error,e:print ' MySQL Error Msg: ', E

Python module ' 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.