Because of the many inconveniences of the. SQLite file operation, it is decided to use MySQL instead of SQLite as the database for the book.
1. Install Mysql-python in a virtual environment The steps are as follows:
<1> Installationpython-dev
sudo apt-get install python-dev
<2> Installationlibmysqlclient-dev
sudo apt-get install libmysqlclient-dev
<3> Installationmysql-python
pip install mysql-python
2. After installation, it is found that the MySQLdb module can be successfully imported in the virtual environment, then the installation is successful, the following is the method of using MySQL instead of SQLite:
<1> Change SQLALCHEMY_DATABASE_URI
variables to:‘mysql://root:[email protected]:3306/BlogTest‘
<2> Create a library named in MySQL BlogTest
create database BlogTest default character
set
utf8 collate utf8_general_ci;
At this point, the database table is empty without any data
<3> Creating database tables and fields
-
Run Mysql, Redit, and celery:
-
$service Redis Start
$service mysqld Start
$celery worker-a celery_worker.celery-l INFO &
-
Create testdata and upgrade to MySQL:
-
$ Python manage.py db init
$ Python manage.py db migrate
$ Python manage.py db upgrade
$ python manage.py datainit
$ python manage.py runserver-h 0.0.0.0
http://blog.csdn.net/kkevinyang/article/details/52183768
Http://www.moguf.com/post/py3flaskmysql
Flask the web with MySQL instead of SQLite