且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ModuleNotFoundError:没有名为"MySQLdb"的模块Amazon MySQL RDS SQLAlchemy

更新时间:2022-01-31 22:19:28

步骤1 如果要使用MySQLDB,则需要使用以下命令之一.哪一个取决于您拥有和使用的操作系统和软件.

Step 1 If you want to use MySQLDB you need to use one of the following commands. Which one depends on what OS and software you have and use.

easy_install mysql-python(混合OS)

pip install mysql-python(mix os/python 2)

pip install mysql-python (mix os/ python 2)

pip install mysqlclient(mix os/python 3)

pip install mysqlclient (mix os/ python 3)

apt-get install python-mysqldb(Linux Ubuntu,...)

apt-get install python-mysqldb (Linux Ubuntu, ...)

cd /usr/ports/databases/py-MySQLdb && make install clean(FreeBSD)

yum install MySQL-python(Linux Fedora,CentOS ...)

yum install MySQL-python (Linux Fedora, CentOS ...)

对于Windows,请参见以下答案:

For Windows, see this answer: Install mysql-python (Windows)

第2步:

  1. 创建引擎

engine = create_engine('mysql+mysqldb://...', pool_recycle=3600)

使用create_engine.pool_recycle选项,以确保如果连接在池中存在固定的秒数,则该连接将被丢弃并替换为新的连接:

use the create_engine.pool_recycle option which ensures that a connection will be discarded and replaced with a new one if it has been present in the pool for a fixed number of seconds:

  1. 创建连接对象

conn = engine.connect()

  1. 执行SQL查询

conn.execute("SELECT * From table;")