“Django 配置MySQL数据库”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
 
第4行: 第4行:
 
apt install mysql-server mysql-client
 
apt install mysql-server mysql-client
 
mysql_secure_installation
 
mysql_secure_installation
 
 
  
 
apt-get install python-dev libmysqld-dev libmysqlclient-dev
 
apt-get install python-dev libmysqld-dev libmysqlclient-dev
第25行: 第23行:
 
     'default': {
 
     'default': {
 
         'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
 
         'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
         'NAME': 'django',                      # Or path to database file if using sqlite3.
+
         'NAME': 'django',                      # 得先建库
 
         # The following settings are not used with sqlite3:
 
         # The following settings are not used with sqlite3:
 
         'USER': 'root',
 
         'USER': 'root',

2021年5月27日 (四) 01:24的最新版本

代码


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',                      # 得先建库
        # 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