Centos6.5 python2.7 Connect MySQL Database

Source: Internet
Author: User
Tags mysql version

1, the environment is centos6.5 32-bit system, Python version is 2.7.12,mysql version is 5.5.22. Prepare the required compression pack, mysql-python-1.2.4b4.tar.gz pip-6.0.7.tar.gz setuptools-12.0.3

2, using Python to operate MySQL first need to import MYSQLDB module, before installing this module finally installed Setuptools and Pip, before this need to install a good zlib zlib-devel module.

#yum install-y zlib-devel bzip2-devel xz-libs xz wget git tar gcc gcc-c++ OpenSSL openssl-devel pcre-devel python-devel l Ibevent automake autoconf libtool make git

Go to Python extract directory, recompile install python2.7 (otherwise error, zlib module can not find)

#./configure--prefix=/usr/local/python27 && make && make install

Setuptools unzip into the post-compression directory, compile and install

Python setup.py Build

Python setup.py Install

I'm done with a soft link to the Easy_install command.

Pip installation Ibid.

3, Decompression Mysql-python bag

Go to Mysql-python Extract directory, vim site.cfg file

Remove mysql_config =/usr/local/mysql/bin/mysql_config before the line, and set the path of the mysql_config correctly (you can use the which mysql_config command to find its path)

Change the Treadsafe=true option to false.

Save exit.

If importing the MySQLdb module fails, error: Importerror:libmysqlclient.so.18:cannot open Shared object file:no such file or directory

According to the last hint, should be unable to find a libmysqlclient.so.18 file, so go to the MySQL installation directory to find this file and make a soft connection to the/usr/lib

Ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18

(If it is a 64-bit system, the previous step should be ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib64/libmysqlclient.so.18)

Import again without an error.

Centos6.5 python2.7 Connect MySQL Database

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.