Python mysqldb quick installation in Linux

Source: Internet
Author: User

Install Python mysqldb in Linux. I found it really hurts to install it by compiling it, but it's just a matter of time, all kinds of problems ......

There are two methods:

A. quick installation

B. compile it by yourself

1. The fastest and easiest way (in a hurry)

Sudo Yum install mysql-Python

Possible problems:
>>> Import mysqldb
Traceback (most recent call last ):
File "<stdin>", line 1, in?
File "mysqldb/_ init _. py", line 22, in?
Raise importerror ("this is mysqldb version % s, but _ MySQL is version % R" %
Importerror: This is mysqldb version (1, 2, 3, 'final', 0), but _ MySQL is version (1, 2, 1, 'final', 1)
Cause: the previous compilation method is used for installation. The following is 1.2.3, but yum is currently used for a maximum of 1.2.1. Conflict
Solution: delete compiled files
Rm-RF Co., MySQL-python-1.2.3/
Proceed
>>> Import mysqldb
If no error exists, it indicates the operation is successful.

2. Compile and install it by yourself (if you have time... Token)

Required:
A. GCC
B. setuptools
Wget-O setuptools-0.6c8.tar.gz unzip sudo easy_install.py [or Python setup. py build & sudo Python setup. py install]
C. Python-Dev in sudo apt-Get install Python-Dev
Otherwise, an exception occurs: Fatal error: Python. h: the file or directory does not exist.

Steps:
A. Download: wget http://sourceforge.net/projects/mysql-python/files/latest/download
B.
$ Tar xfz MySQL-python-1.2.3.tar.gz
$ MySQL-python-1.2.3 CD
$ Whereis mysql_config
Mysql_config:/usr/bin/mysql_config
$ Vim site. cfg
Modify mysql_config to the MySQL configuration file path/usr/bin/mysql_config
Also modify
Threadsafe = false
$ Python setup. py build
$ Sudo Python setup. py install

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.