安装python-mysqldb
只支持python2.x方式一:执行命令
sudo apt-get install python-mysqldb
方式二:使用pip安装
pip install mysql-python
报错:EnvironmentError: mysql_config not found
执行:sudo apt-get install libmysqld-dev
重新执行pip命令安装
方式三:使用Pycharm IDE的包管理器,搜索mysql,选择安装
方式四:源码包安装
python setup.py install
安装mysql-connector
MySQL官方驱动包,支持python3.x
pip install mysql-connector-python
安装mysqlclient
是对python-mysqldb的封装,支持Python2.x和3.x。建议使用此模块操作mysql数据库。pypi地址:https://pypi.python.org/pypi/mysqlclient/1.3.12
github地址:https://github.com/PyMySQL/mysqlclient-python
Prerequisites
You may need to install the Python and MySQL development headers and libraries like so:
sudo apt-get install python-dev libmysqlclient-dev # Debian / Ubuntu
sudo yum install python-devel mysql-devel # Red Hat / CentOS
On Windows, there are binary wheel you can install without MySQLConnector/C or MSVC.
Note on Python 3 : if you are using python3 then you need to install python3-dev using the following command :
sudo apt-get install python3-dev # debian / Ubuntu
sudo yum install python3-devel # Red Hat / CentOS
brew install mysql-connector-c # macOS (Homebrew)
Install from PyPI
pip install mysqlclient
NOTE: Wheels for Windows may be not released with source package. You should pin version in your requirements.txt
to avoid trying to install newest source package.
Install from source
1.Download source by git clone or zipfile.
2.Customize site.cfg
3.python setup.py install
 
                   
                   
                   
                   本文介绍了如何在Python环境中安装连接MySQL数据库所需的驱动包,包括使用pip安装mysql-connector-python和mysqlclient,确保在Python3.x环境下顺利进行数据库操作。
本文介绍了如何在Python环境中安装连接MySQL数据库所需的驱动包,包括使用pip安装mysql-connector-python和mysqlclient,确保在Python3.x环境下顺利进行数据库操作。
           
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   5067
					5067
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            