Django uses MySQL

Source: Internet
Author: User

1. According to the Django official website documents https://docs.djangoproject.com/en/1.5/intro/tutorial01/ step by step installation successful, modify the setting. py, execute

python manage.py syncdb

Throw the following exception:

Django. Core. Exceptions. improperlyconfigured: error loading mysqldb module: No module named mysqldb

2. google's related information indicates that mysql-python is not installed, and Yum install mysql-python is installed, prompting that the local machine has an updated version, but Python manage is executed. PY sycndb still prompts the same error.

One problem on stackoverflow: http://stackoverflow.com/questions/2952187/getting-error-loading-mysqldb-module-no-module-named-mysqldb-have-tried-pre

I have no Pip command on the local machine and have not studied it. Execute the command: easy_install
Mysql-Python:

The required
Version of distribute (> = 0.6.28) is not available,
And can't be installed while this script is running. Please
Install a more recent version first, using
'Easy _ install-u distriket '.

Execute easy_install
-U distribute. After installation is successful, execute easy_install mysql-Python again!

3. Execute again:

python manage.py syncdb

When setting. py is set to null, the following error occurs: operationalerror:
(1045, "Access denied for user 'root' @ 'localhost' (using password: No )")

But there is no problem in viewing the MySQL database, host + User Name + password.

Note that the line for setting host in setting. py has a comment: empty for localhost through domain sockets or '192. 0.0.1 'For localhost through TCP.

My host is configured with 127.0.0.1, which means it will be connected through TCP. If it is null, it will be connected through socket, so it will be changed to 127.0.0.1, and then run Python manage. py syncdb, which is created successfully.

Note the following in the setting. py file:

Databases = {
'Default ':{
'Engine ': 'django. DB. backends. mysql', # Add 'postgresql _ psycopg2', 'mysqlite3 ', or 'oracle '.
'Name': 'djangotest', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'User': 'root ',
'Password ':'',
'Host': '2017. 0.0.1 ', # Empty for localhost through domain sockets or '2017. 0.0.1' For localhost through TCP.
'Port': '123', # Set to empty string for default.
}
}

Here, the 'name' value indicates the name of the database. The database must be created in advance. Django will not create a database for you. It is also described in Django documentation.

Related Article

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.