django中mysql配置及使用

# Django settings for mysite2 project.

 

DEBUG = True

TEMPLATE_DEBUG = DEBUG

 

ADMINS = (

    # ('Your Name', '[email protected]'),

)

 

MANAGERS = ADMINS

 

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.

        'NAME': 'test',                      # Or path to database file if using sqlite3.

        'USER': 'root',                      # Not used with sqlite3.

        'PASSWORD': 'root',                  # Not used with sqlite3.

        'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.

        'PORT': '3306',                      # Set to empty string for default. Not used with sqlite3.

    }

}

 

# Local time zone for this installation. Choices can be found here:

# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name

# although not all choices may be available on all operating systems.

# In a Windows environment this must be set to your system time zone.

TIME_ZONE = 'America/Chicago'

 

# Language code for this installation. All choices can be found here:

# http://www.i18nguy.com/unicode/language-identifiers.html

LANGUAGE_CODE = 'en-us'

 

SITE_ID = 1

 

# If you set this to False, Django will make some optimizations so as not

"settings.py" 151L, 5241C written                                                                        

root@ubuntu118:/home/python/work/mysite2/mysite2# python ../manage.py syncdb

Creating tables ...

Creating table auth_permission

Creating table auth_group_permissions

Creating table auth_group

Creating table auth_user_user_permissions

Creating table auth_user_groups

Creating table auth_user

Creating table django_content_type

Creating table django_session

Creating table django_site

 

You just installed Django's auth system, which means you don't have any superusers defined.

Would you like to create one now? (yes/no): y

Please enter either "yes" or "no": yes

Username (leave blank to use 'root'):

E-mail address:

Error: That e-mail address is invalid.

E-mail address: 126170^H

Error: That e-mail address is invalid.

E-mail address: [email protected]

Password:

Password (again):

Superuser created successfully.

Installing custom SQL ...

Installing indexes ...

Installed 0 object(s) from 0 fixture(s)

root@ubuntu118:/home/python/work/mysite2/mysite2# ll

total 32

drwxr-xr-x 2 root root 4096 Oct 11 16:46 ./

drwxr-xr-x 3 root root 4096 Oct 11 15:38 ../

-rw-r--r-- 1 root root    0 Oct 11 15:38 __init__.py

-rw-r--r-- 1 root root  132 Oct 11 16:27 __init__.pyc

-rw-r--r-- 1 root root 5241 Oct 11 16:46 settings.py

-rw-r--r-- 1 root root 2865 Oct 11 16:46 settings.pyc

-rw-r--r-- 1 root root  559 Oct 11 15:38 urls.py

-rw-r--r-- 1 root root 1136 Oct 11 15:38 wsgi.py

root@ubuntu118:/home/python/work/mysite2/mysite2# cd ..

root@ubuntu118:/home/python/work/mysite2# ll

total 16

drwxr-xr-x 3 root   root   4096 Oct 11 15:38 ./

drwxrwxr-x 5 python python 4096 Oct 11 15:38 ../

-rwxr-xr-x 1 root   root    250 Oct 11 15:38 manage.py*

drwxr-xr-x 2 root   root   4096 Oct 11 16:46 mysite2/

root@ubuntu118:/home/python/work/mysite2# cd mysite2

root@ubuntu118:/home/python/work/mysite2/mysite2# ll

total 32

drwxr-xr-x 2 root root 4096 Oct 11 16:46 ./

drwxr-xr-x 3 root root 4096 Oct 11 15:38 ../

-rw-r--r-- 1 root root    0 Oct 11 15:38 __init__.py

-rw-r--r-- 1 root root  132 Oct 11 16:27 __init__.pyc

-rw-r--r-- 1 root root 5241 Oct 11 16:46 settings.py

-rw-r--r-- 1 root root 2865 Oct 11 16:46 settings.pyc

-rw-r--r-- 1 root root  559 Oct 11 15:38 urls.py

-rw-r--r-- 1 root root 1136 Oct 11 15:38 wsgi.py

root@ubuntu118:/home/python/work/mysite2/mysite2#

 

root@ubuntu118:/home/python/work/mysite2/mysite2# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 52

Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)

 

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| hive               |

| mydatabase         |

| mysql              |

| performance_schema |

| test               |

+--------------------+

6 rows in set (0.00 sec)

 

mysql> use test;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

mysql> show tables;

+----------------------------+

| Tables_in_test             |

+----------------------------+

| auth_group                 |

| auth_group_permissions     |

| auth_permission            |

| auth_user                  |

| auth_user_groups           |

| auth_user_user_permissions |

| django_content_type        |

| django_session             |

| django_site                |

| test                       |

+----------------------------+

10 rows in set (0.00 sec)

你可能感兴趣的:(django中mysql配置及使用)