Connect to Mysql using python in Linux

Source: Internet
Author: User

To import the user accounts and passwords in the blog into the FTP database, you can directly use the blog account to log on to FTP. I decided to use python in Linux to help me deal with it. This log is a brief introduction, using python to connect to Mysql.

1. Install the MySQLdb module in Linux
To connect to Mysql using python, you need an interface for connecting python to Mysql, which is the MySQLdb module.
Functions of MySQLdb:

MySQL support for Python. mySQL versions 3.23-5.1; and Python versions 2.3-2.5 are supported. mySQLdb is the Python DB API-2.0 interface. _ mysql is a low-level API similiar to the MySQL c api. ZMySQLDA is a Database Adapter for Zope2.

In the operating system of red-flag Linux, the MySQL-python module with version 1.0.0 is used by default:

Reference
# Rpm-qa | grep MySQL
MySQL-python-1.0.0-1.RHEL4.1

However, it is found that the version of this module is too old, and the support for Mysql 4.1 or above is incomplete, and even a Bug exists in help. Therefore, we recommend that you upgrade to a new version.

1. Install the new version
You can download and compile it by yourself. You can also use the compiled rpm package:

See the final attachment.

※This rpm package is applicable to systems with the red-flag DC Server 5.0 for x86 SP2 and python 2.3. Compile and use other systems on your own.
In addition, the MySQLdb module of version 1.2.2 cannot be compiled successfully on CentOS 5 and used on CentOS 5. You can use its own version 1.2.1.

2. Compile and install
The python and Mysql versions supported by MySQLdb of the new version 1.2.2 are different from those of the old version. See the README file in the source code.
If you do not use the rpm Method for installation, You can manually compile and install the command as follows:

# Cd/usr/local/src/MySQL-python-1.2.2/
# Python setup. py build
# Python setup. py install

If you do not have the setuptools module in your python environment, you must connect to the Internet during compilation. It will download the setuptools module from the Internet and generate a. egg compression module file for future use.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Next Page

Related Article

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.