Django 配置MySQL数据库
docker>Evan2017年10月19日 (四) 06:22的版本 (→代码)
代码
apt install mysql-server mysql-client mysql_secure_installation apt-get install python-dev libmysqld-dev libmysqlclient-dev pip install mysql-python Django(Python)操作MySQL依赖第三方包,所以要先安装MySQL for Python。 $ wget https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip $ unzip MySQL-python-1.2.5.zip $ sudo python setup.py install #配置 # #CREATE DATABASE ch07www CHARACTER SET utf8; # settings.py Database # https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'django', # Or path to database file if using sqlite3. # The following settings are not used with sqlite3: 'USER': 'root', 'PASSWORD': '1234', 'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 'PORT': '3306', # Set to empty string for default. } }
参考
https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-notes
DJANGO+MYSQL安装配置详解(LINUX)[更新为1.8.2版]
https://docs.djangoproject.com/en/1.8/ref/settings/#databases
https://shenxgan.gitbooks.io/django/content/publish/2015-07-13-django-mysql.html