Flask Web中用MySQL代替SQLite

由于.sqlite文件操作的诸多不便,决定常识用MySQL代替书上的SQLite作为数据库
1.在虚拟环境中安装mysql-Python具体步骤为:
<1> 安装python-dev

sudo apt-get install python-dev

<2>安装 libmysqlclient-dev

sudo apt-get install libmysqlclient-dev

<3>安装mysql-python

pip install mysql-python

2.安装完成后发现MySQLdb模块在虚拟环境中可成功导入,则说明安装成功,下面是使用mysql代替sqlite的方法:

<1>更改SQLALCHEMY_DATABASE_URI变量为:'mysql://root:thinkive@127.0.0.1:3306/BlogTest'

Flask Web中用MySQL代替SQLite <2>在mysql中创建名为BlogTest的库

create database BlogTest default character set utf8 collate utf8_general_ci;

Flask Web中用MySQL代替SQLite

此时,数据库表里是空的没有任何数据

<3>创建数据库表和字段

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

上一篇:Spring Boot + Spring Cloud 构建微服务系统(六):熔断监控集群(Turbine)


下一篇:Linux 之集群 LVS