Install MySQLdb on RedHat

Source: Internet
Author: User
One thing that should have been simple and smooth, but encountered a lot of trouble in the actual process. For a new linux user, it is very easy to get stuck, so simply write it down, in this way, we can make progress every day! There is a ready-made MySQL-python-1.2.3 version on hand, it is relatively new, and the python on the machine is still 2.4, I think a little old, so I want to upgrade python, A Python source code package also exists, so the upgrade starts. The specific command is: Upgrade py

One thing that should have been simple and smooth, but encountered a lot of trouble in the actual process. For a new linux user, it is very easy to get stuck, so simply write it down, in this way, we can make progress every day!

There is a ready-made MySQL-python-1.2.3 version on hand, it is relatively new, and the python on the machine is still 2.4, I think a little old, so I want to upgrade python, A Python source code package also exists, so the upgrade starts. The specific command is:

Upgrade python

Tar zxvf python2.5.4.tar.gz

Cd python2.5.4

./Configure

Make

Make install

Check the python version

Run python-V

It is strange that it still shows 2.4.3. After query, this is because the python command is directly executed and the usr/bin/python command is executed. This is actually a hard connection of python2.4.3, can I change it to a hard connection of python2.5.4? Execute:

Modify the default python version

Ln-s/usr/bin/python2.5/usr/bin/python

Execute python-V again. If the prompt is correct, it indicates that the upgrade is successful. In addition, I feel relieved to use the source code package for installation, although it takes a little longer.

Next, install MySQLdb. Follow README to execute python setup. py build and find various errors. Then, check that you should first execute python ez_setup.py and automatically download an installation tool. This step is correct, but the system prompts that zlib cannot be found. The error message is as follows:

Zipimport. ZipImportError: can't decompress data; zlib not available

Grandma's, it's really troublesome, So I downloaded a zlib source code package for installation. Note: After zlib is installed, recompile python !!!!

Run python setup. py build, and prompt that mysql cannot be found. h and other header files. In another blog, the solution is to download a mysql-devel .... rpm package. After installation, these required header files are available in/usr/include/mysql. Unfortunately, a mysql version 5.0.7 is available on the machine. The devel package I downloaded is 5.1.4 and runs rpm-ivh mysql-devel... after rpm, a version conflict is prompted, so I want to uninstall mysql and execute:

Uninstall the old version of msyql

Rpm-qa | grep mysql

Run

Rpm-ev qt-msyql -.....

Rpm-ev mysql-5.0.7 .....

Uninstalled

After installing the new version of the msyql-devel package, the header file already exists. Install MySQLdb again:

Install the MySQLdb Module

Python setup. y build

Python setup. py install

Very smooth

Detect MySQLdb

Go to python and execute import MySQLdb. If the prompt is correct, it will be OK. Sometimes it will prompt a bunch of messy things. It doesn't matter. If you are not at ease, execute the Connection method of MySQLdb to connect to a database and you will know whether the Connection is successful or not!

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.