django1.5.5使用mysql

pythn3.3下实现django1.5.5连接mysql

   django1.5.5发布有一段时间了,最大的亮点在于支持python3.在版本上跟进了python3的各种应用。而在数据库方面,django1.5.5的mysqldb却还停止不前。幸在有mysql自发布的connector python连接器对python3的支持。准备工作(本文在win7,64位下实现):

   1.python3.3的安装  http://www.python.org/ftp/python/3.3.2/python-3.3.2.amd64.msi 直接安装在c:\python3.3

   2.安装了pycharm3.0,自动安装pip.设置脚本环境path:c:\python\scripts;c:\python33\

   3.安装django 1.5.5 在cmd下面:pip install django==1.5.5 自动完成安装后,弹出一列注意的事项。

   4.安装mysql 6.5 http://dev.mysql.com/downloads/mirror.php?id=414474

   5.安装mysql connector /python 稳定版  alpha版(稳定版没有django版块,网上说:先安装完alpha版,然后copy version.py,再安装稳定版,把version.py覆盖。本人刚好是相反的安装,没有发现问题)修改django目录下的base.py第278行,由 #return cursor.statement.decode('utf-8')改成   return cursor

   6.运行 python-admin.py startproject oursite,在当前目录下产生一个oursite文件夹。  

   7.参考mysql connector python中修改oursite中的setting.py中datatabase:http://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html

   8.测试语句:

      python manage.py shell

      from django.db import connection

      cursor=connection.cursor()

      cursor.execute("select * from yourtable")

      cursor.fetchone()

 

    9.完成。

 

posted on 2013-10-26 15:08  pikewu  阅读(263)  评论(0)    收藏  举报

导航