I am having issues with connecting Amazon AWS MySQL with SQLAlchemy. According to the instruction, I have connected.
app.config[\'SQLALCHEMY_DATABASE_URI\'] = \'
Above issues has been solved with the following:
import pymysql
pymysql.install_as_MySQLdb()
Nothing to change anywhere.
If you use the PyMySQL client to connect to MySQL, your SQLAlchemy connection string needs to start with
mysql+pymysql://
instead of mysql://
.
If you connect with mysql://
then you will need to install the MySQLdb library as shown in the Traceback.
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
(mix os)
pip install mysql-python
(mix os/ python 2)
pip install mysqlclient
(mix os/ python 3)
apt-get install python-mysqldb
(Linux Ubuntu, ...)
cd /usr/ports/databases/py-MySQLdb && make install clean
(FreeBSD)
yum install MySQL-python
(Linux Fedora, CentOS ...)
For Windows, see this answer: Install mysql-python (Windows)
Step 2:
engine = create_engine('mysql+mysqldb://...', pool_recycle=3600)
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:
conn = engine.connect()
conn.execute("SELECT * From table;")