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

来自linux中国网wiki
跳到导航 跳到搜索
(导入1个版本)
 
(未显示同一用户的3个中间版本)
第4行: 第4行:
 
apt install mysql-server mysql-client
 
apt install mysql-server mysql-client
 
mysql_secure_installation
 
mysql_secure_installation
 
+
apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config apt-get install python-dev libmysqld-dev libmysqlclient-dev
 
 
 
 
apt-get install python-dev libmysqld-dev libmysqlclient-dev
 
  
 
pip install mysql-python
 
pip install mysql-python
 +
pip3 install mysqlclient
  
  
第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',
第44行: 第42行:
  
 
https://shenxgan.gitbooks.io/django/content/publish/2015-07-13-django-mysql.html
 
https://shenxgan.gitbooks.io/django/content/publish/2015-07-13-django-mysql.html
[[category:django]]
+
[[category:django]]  [[category:ops]]

2024年11月1日 (五) 09:14的最新版本

代码


apt install mysql-server mysql-client
mysql_secure_installation
apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config apt-get install python-dev libmysqld-dev libmysqlclient-dev

pip install mysql-python
pip3 install mysqlclient


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