How to use MySQL in Django1.6 combined Python3.3 version

Source: Internet
Author: User

Alas, recently rushed a trendy, with the Python3.4 and Django1.6, the database is still the Internet Enterprise common MySQL.

Sad reminder is in Python2.7 ERA connection MySQL MYSQLDB also not support Python3.4, fortunately, hard to ask G brother finally found a substitute, and the effect is good, this substitute is: Pymysql.

Download this and install it, no different than the other Python third package, the same installation.

The same thing about databases in Django1.6 is that you don't have to make any changes, as you did in the previous mysqldb, as follows:

1 DATABASES = {2     ' default ': {3         ' ENGINE ': ' Django.db.backends.mysql ', #数据库引擎 4         ' NAME ': ' Test ',                       #数据库名 5
    ' USER ': ' Root ',                       #用户名 6         ' PASSWORD ': ' Root ',                   #密码 7         ' HOST ': ',                           #数据库主机, default to localhost 8         ' PORT ': ',                           #数据库端口, MySQL defaults to 3306 9         ' OPTIONS ': {ten             ' autocommit ': true,11         },12     }13}

The most critical point, in the site's __init__.py file, we add the following code:

1 Import pymysql2 pymysql.install_as_mysqldb ()

Once you've done this, you'll be able to access MySQL in Django.

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.