安装Mysql¶
sudo apt-get install mysql-server
sudo apt-get install python-mysqldb
sudo apt-get install libmysqlclient-dev
安装mysql-python
模块¶
pip install mysql-python
创建并设置Database¶
mysql -u root -p
Enter password:
###mysql> CREATE DATABASE tulpar_db;(最好用下面的方法,创建数据库时指定编码,免得不识别汉字
mysql> CREATE DATABASE tulpar_db CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> GRANT ALL ON tulpar_db.* TO 'tulpar'@'localhost' IDENTIFIED BY 'mypassword';
Query OK, 0 rows affected (0.03 sec)
mysql> quit
Bye
设置django settings¶
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME':'tulpar_db',
'USER' :'tulpar', # Not used with sqlite3.,
'PASSWORD' : 'mypassword', # Not used with sqlite3.
'HOST' : '', # Set to empty string for localhost. Not used with sqlite3.
'PORT' : '', # Set to empty string for default. Not used with sqlite3.
}
}
生成数据¶
python manage.py syncdb
python manage.py runserver