Django uses MySQL database

Source: Internet
Author: User

After configuring the MySQL database according to the previous tutorial, create a Django project based on the MySQL database! (Summary of the tossing process is not well written. You are welcome to make a picture !) Create a MySQL database first! The procedure is as follows:

1. Check whether MySQL is running

Enter termial and PS-E | grep mysqld.

If similar results are displayed, the operation is correct:

2. Create a User Root and enter the password.
/Usr/local/mysql-5.6.11-osx10.7-x86_64/bin/MySQL-u root-P // a large string of path in front of MySQL path, you find the root for the database line based on their own installation path to create the user

Then you will be asked to enter the password: (the password can be blank)

3. Create a database for the user (datadb)
Mysql> Create Database datadb; (do not forget the semicolon)

If you install MySQL workbench, you can set the connection here:


Click "OK". Then you can see the database you just created in it:


4. connect to and manage the database here:


5. If it succeeds, you can click "continue" until the MySQL database is created:

6. I use eclipse to develop Django, create a new Django project, and use the MySQL database:

Modify settings. py:

Note: 'name': name of the database you created

'User': the user created when you created the database.

'Host': The local address localhost

'Port': Specifies the port address.


So far, select project:


In this case, the console outputs the following information. create the first user when py syncdb is created. If you need to use the admin module of Django, the user created at this time is the user name and password you have obtained during background management Logon:


The MySQL database is successfully created!

7. Run the project. Open http: // 127.0.0.1: 8000/admin/(the admin module is omitted here. Check the information for yourself !)




Pay for commonly used MySQL operation instructions:

// Delete a user
Mysql> Delete from user where user = "phplamp" and host = "localhost ";
// Delete the user's database
Mysql> drop database phplampdb;

// Create a user
Mysql> insert into mysql. User (host, user, password) values ('localhost', 'user', password ('123 '));
// Refresh the system permission list
Mysql> flush privileges;

// Log on after exiting
Mysql> exit;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.