Python's MySQLdb Learning notes

Source: Internet
Author: User


Create a new mysql.py and write the following code:

The code is as follows Copy Code
Import MySQLdb

After the operation found Importerror:no module named MySQLdb, that your Python environment is not installed MYSQLDB This module, then go to install Bai, do not install does not matter, one installation of various problems AH.


First I use the command pip install Mysql-python, a wait, throw an "error can not find Mysql_config", I said no ability to change this error, a search to determine their own source code compiled installation.


First go to this site under http://sourceforge.net/projects/mysql-python/, after the good after the direct decompression. Then run the sudo python setup.py build and report a mistake IOERROR:CRC check failed, which Nima what the error is. Have not encountered the error, but also a search, someone suggested that there may be a compression error. I just thought I was a Mac, maybe it's a problem, run the command

The code is as follows Copy Code

TAR-ZXVF mysql-xx.tar.gz.

CD./mysql-xx

sudo python setup.py build

It's finally done.

But mistakes always follow an unprepared person to report the error can not find mysql_config with PHP install reported the same mistake, with the source code we can change it, and finally a brother search the setup_posix.py put inside the

The code is as follows Copy Code
Mysql_config.path = "Mysql_config" #改为 the mysql_config path of the local computer

Continue to the next step Python setup.py build, OK finally perfect, then go to run mysql.py error again, this tip

Reason:image not found, all right, we have to go to the search, the problem is easy to solve, direct Run command

The code is as follows Copy Code
sudo ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib/libmysqlclient.18.dylib


Well, finally, I can use it, tears running.


PS: Run the command or add a sudo, otherwise there will be some unknown problems.

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.