Now basically nothing can get away from the database, Django I have been using the MySQL database, this time and you talk about the Django--mysql database of some common command bar
1: Command line login MySQL
C:\users\administrator>mysql-uroot-********
2: Create a new database and use it
mysql>1 row affected (0.02 sec) MySQL> Use t;database changed
3: A little attention to the problem, we first practice show
Mysql> Show create database t; +----------+--------------------------------------------------------------+| Database | Create Database |+----------+--------------------------------------------------------------+| t/ * latin1* /|+----------+--------------------------------------------------------------+ 1 in Set (0.00 sec)
Note that the character set is Latin1
In this way, we can not save Chinese, the following we change the setting, the specific command I will not explain, I believe we can read
Mysql> Show variables like'char%';+--------------------------+---------------------------------------------------------+| variable_name |Value|+--------------------------+---------------------------------------------------------+| character_set_client |latin1|| character_set_connection |latin1|| Character_set_database |latin1|| Character_set_filesystem |binary|| Character_set_results |latin1|| Character_set_server |latin1|| Character_set_system |UTF8|| Character_sets_dir | C:\Program Files\mysql\mysql Server5.5\share\charsets\|+--------------------------+---------------------------------------------------------+8RowsinchSet (0.01sec) MySQL>set names UTF8; Query OK,0Rows Affected (0.01sec) MySQL> Show variables like'char%';+--------------------------+---------------------------------------------------------+| variable_name |Value|+--------------------------+---------------------------------------------------------+| character_set_client |UTF8|| character_set_connection |UTF8|| Character_set_database |latin1|| Character_set_filesystem |binary|| Character_set_results |UTF8|| Character_set_server |latin1|| Character_set_system |UTF8|| Character_sets_dir | C:\Program Files\mysql\mysql Server5.5\share\charsets\|+--------------------------+---------------------------------------------------------+8RowsinchSet (0.00sec) MySQL> Set character_set_database ='UTF8'; Query OK,0Rows Affected (0.00sec) MySQL> Set character_set_server ='UTF8'; Query OK,0Rows Affected (0.00sec) MySQL> Show variables like'char%';+--------------------------+---------------------------------------------------------+| variable_name |Value|+--------------------------+---------------------------------------------------------+| character_set_client |UTF8|| character_set_connection |UTF8|| Character_set_database |UTF8|| Character_set_filesystem |binary|| Character_set_results |UTF8|| Character_set_server |UTF8|| Character_set_system |UTF8|| Character_sets_dir | C:\Program Files\mysql\mysql Server5.5\share\charsets\|+--------------------------+---------------------------------------------------------+8RowsinchSet (0.00Sec
3: Then delete the database that was created in 1, 2 steps, DROP database name is OK, then recreate it.
4: Configure the config file in Django now
DATABASES = { 'default': { 'ENGINE':'Django.db.backends.mysql',#Add ' postgresql_psycopg2 ', ' MySQL ', ' sqlite3 ' or ' Oracle '. 'NAME':'Irsearch',#Or Path to database file if using Sqlite3. 'USER':'Root',#Not used with sqlite3. 'PASSWORD':' The password for your database',#Not used with sqlite3. 'HOST':'127.0.0.1',#Set to empty string for localhost. Not used with Sqlite3. 'PORT':"',#Set to empty string for default. Not used with Sqlite3. }}
5: Write model.py, simple example, attention must use Models.model, otherwise useless
#-*-coding:utf-8-*- fromDjango.dbImportModels#Create your models here.classWeibo (models. Model):"""docstring for Weibo"""w_id= Models. Integerfield (primary_key=True) UserID= Models. Charfield (max_length=20) Username= Models. Charfield (max_length=30) Content= Models. Charfield (max_length=2000) Ptime= Models. Charfield (max_length=20) Count= Models. Integerfield ()
SQL operations for 6:django
Python manage.py syncdb Initialize the database or update the database
Python manage.py SQL + database name
Python manage.py SQL + database name > T.sql allows this data to be written to t.sql and can be used directly
6:mysql Data Import and export
In fact, it is strongly not recommended to use MySQL data import and export, you can read the database directly in the background to import and export data in the database
c:\users\administrator>mysqldumpusage:mysqldump [OPTIONS] Database [Tables]or --databases [ OPTIONS] DB1 [DB2 DB3 ...] OR --all---help database name table name C:\Users\Administrator>mysqldump-uroot-p irsearch Search_stop >********
Then you can see the stop.txt in the current directory, preferably output to a SQL file, and then you can import SQL directly
If you are importing the Sina SAE database, remember that the lock,unlock instruction inside is removed, because the SAE does not give you the command permission
Finally must remind everybody, pay attention to the database storage format , otherwise you will cry, believe me