如何在Django中配置和使用MySQL? [英] How to configure and use MySQL with Django?

查看:46
本文介绍了如何在Django中配置和使用MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ubuntu 14.04系统,并且还创建了一个虚拟环境.我想用MySQL数据库(最好是PHPMyAdmin)设置Django来处理我的项目.请用所需的命令指导我并设置线路.

I am using Ubuntu 14.04 system and have created a virtual environment also. I want to set up Django with MySQL database (PHPMyAdmin preferably) to work on my project. Please guide me with the required commands and set up lines.

推荐答案

您可以先从 https轻松地安装xampp://www.apachefriends.org/download.html

(按照这些步骤进行xampp安装.)

(Follow these steps for xampp installation.)

然后按照以下说明进行操作:

Then follow the instructions as:

  1. http://www.unixmen安装并运行xampp.com/install-xampp-stack-ubuntu-14-04/,然后从GUI启动Apache Web Server和MySQL数据库.
  2. 您可以根据需要配置Web服务器,但默认情况下,Web服务器位于 http://localhost:80 ,数据库位于 port 3306 ,而PhpMyadmin位于<代码> http://localhost/phpmyadmin/
  3. 从这里您可以查看您的数据库,并使用非常友好的GUI访问它们.
  4. 创建要在Django项目上使用的任何数据库( DB_NAME ).
  5. 编辑您的settings.py文件

  1. Install and run xampp from http://www.unixmen.com/install-xampp-stack-ubuntu-14-04/, then start Apache Web Server and MySQL Database from the GUI.
  2. You can configure your web server as you want but by default web server is at http://localhost:80 and database at port 3306, and PhpMyadmin at http://localhost/phpmyadmin/
  3. From here you can see your databases and access them using very friendly GUI.
  4. Create any database(DB_NAME) which you want to use on your Django Project.
  5. Edit your settings.py file

DATABASES = {'默认': {'ENGINE':'django.db.backends.mysql','NAME':'DB_NAME','主机':'127.0.0.1','PORT':'3306','USER':'root','PASSWD':'',}}

在virtualenv中安装以下软件包(如果您在virtualenv上使用django,则更可取):

Install the following packages in the virtualenv (if you're using django on virtualenv, which is more preferred):

sudo apt-get install libmysqlclient-dev

pip安装MySQL-python

就是这样!您已经以一种非常简单的方式使用MySQL配置了Django.

That's it!! you have configured Django with MySQL in a very easy way.

现在运行您的Django项目:

Now run your Django project:

python manage.py migration

python manage.py runserver

这篇关于如何在Django中配置和使用MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆