Flask the web with MySQL instead of SQLite

Source: Internet
Author: User
Tags sqlite virtual environment

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 setutf8 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.