• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

python2.7中使用mysql (windows XP)

一.首先下载mysql—python模块,下载完毕之后会有一个MySQL-python-1.2.3.win32-py2.7.exe文件,点击安装一路next,ok。


二.编辑配置文件(setting.py)


 

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'blog',                     # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}


注意:我的一个数据库叫名叫blog

 


三.django连接

1.在cmd命令框中进入project目录,输入 python manage.py shell

2.输入: >>>from django.db import connection

                >>>cursor=connection.cursor()


如果什么问题都没有,说明配置正确 。(别忘了开启你的mysql服务)


 

posted @ 2013-09-27 18:58  Class Xman  阅读(225)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3