Flask Web Development----using MySQL Database

Source: Internet
Author: User
Tags sqlite sqlite database python mysql

According to the Flask web Development book, it is not recommended to use SQLite in a production environment, so when I follow the book and finish the code in the API chapter, I'm going to switch the database to MySQL.

1. Delete these two files now, as this is a file related to the SQLite database previously used

2. Modify the address of the database in the config file in the original project to the MySQL database. You need to install the MySQL database on your native computer now, and you have a user account for: root, Password: root, the database name created is flask. (There is no too much explanation for MySQL here)

For security reasons, you can pass the path



3. You need to install Python MySQL support for your environment at this time

Installing mysql-python-1.2.3 Steps


1> first download in the browser http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download

2> Enter this folder input command: Tar zxf mysql-python-1.2.3.tar.gz && CD mysql-python-1.2.3

3>python setup.py Build
4>python setup.py Install

If Environmenterror:mysql_config not found is reported when executing the Python setup.py build, find the location of Mysql_config first, using Find/-name mysql_config , I was in the/usr/local/mysql/bin/mysql_config, and then modify the mysql-python-1.2.3 directory site.cfg file, remove mysql_config=xxx This line of comments, and changed to Mysql_ Config=/usr/local/mysql/bin/mysql_config, whichever is his own machine.

4. Now you can create a script for data migration

Python manage.py DB init

Python manage.py db migrate-m "Initial migration"

Python manage.py DB Upgrade

After executing these commands, these tables should be present in your MySQL database.

Flask Web Development----using MySQL Database

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.