Python下的Mysql模块MySQLdb安装详解
默认情况下,MySQLdb包是没有安装的,不信? 看到类似下面的代码你就信了。
代码如下:
-bash-3.2# /usr/local/python2.7.3/bin/python get_cnblogs_news.py
Traceback (most recent call last):
File "get_cnblogs_news.py", line 9, in
import MySQLdb
ImportError: No module named MySQLdb
这时我们就不得不安装MySQLdb包了。安装其实也挺简单,具体步骤如下:
1、下载 MySQL for Python
地址:http://sourceforge.net/projects/mysql-python/files/mysql-python/
我这里安装的是1.2.3版本
代码如下:
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
2、解压
代码如下:
tar zxvf MySQL-python-1.2.3.tar.gz
3、安装
代码如下:
$ cd MySQL-python-1.2.3
$ python setup.py build
$ python setup.py install
注:
如果在执行:python setup.py build 遇到以下错误:
代码如下:
EnvironmentError: mysql_config not found
首先查找mysql_config的位置,使用
find / -name mysql_config ,比如我的在/usr/local/mysql/bin/mysql_config
修改setup_posix.py文件,在26行:
mysql_config.path = “mysql_config” 修改为:
代码如下:
mysql_config.path = “/usr/local/mysql/bin/mysql_config”
保存后,然后再次执行:
代码如下:
python setup.py build
python setup.py install
OK,到此大功告成。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Discussion on Hierarchical Structure in Python Projects In the process of learning Python, many beginners will come into contact with some open source projects, especially projects using the Django framework...

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...
