django,phpmyadmin和mysql? [英] django, phpmyadmin and mysql?

查看:232
本文介绍了django,phpmyadmin和mysql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一直使用Django和MYSQL,而不是一直使用sqlite,但是我使用MSQL的唯一经验是通过XAMPP,通过phpmyadmin操纵数据库.我真的很想保持与gui的gui交互,而不必通过命令行做所有事情.

I would like to start using Django with MYSQL, instead of sqlite all the time, however my only experience using MSQL is through XAMPP, manipulating databases through phpmyadmin. I would really like to keep this gui interaction with mysql and not have to do everything through command line.

您可以使用xampp/phpmyadmin启动和管理MYSQL数据库,然后仅通过Django的n开发服务器将django用于Web开发吗?

Can you start and manage a MYSQL database using xampp/phpmyadmin, and then use django for the web development side only using Django'sn development server?

还是您必须始终通过命令行启动新数据库,如果是这样,如何做,请记住我只通过xampp/phpmyadmin使用mysql吗?

Or do you have to always start new databases through command line, and if so how is it done, bearing in mind I only ever use mysql through xampp/phpmyadmin?

我知道如何通过django链接和管理数据库,我只是不知道如何通过它来启动mysql,而且我真的不想放弃xampp/phpmyadmin随附的mysql gui.感谢所有帮助.

I know how to link and manage a database through django, I just dont know how to start a mysql one through it, and I dont really want to have to loose the mysql gui that comes with xampp/phpmyadmin. all help is greatly appreciated.

推荐答案

您绝对可以通过XAMPP接口管理Mysql.尝试将settings.py中的DB_HOST设置为"localhost".如果不起作用,请尝试"127.0.0.1".这通常是由python-mysql模块导致,它期望mysql unix套接字位于其他位置.实际上,我不确定mysql服务器是否在Windows上使用unix套接字.无论如何,两者都应该工作:) 您也可以使用用于phpmyAdmin登录的凭据(也适用于Django).许多人认为将root用户用于非管理任务是一种不好的方式(我同意),但是对于初学者和开发计算机而言,这并不是一个大问题. phpMyAdmin应该可以与Django管理的数据库一起使用.

You can definitely manage Mysql through the XAMPP interface. Try setting the DB_HOST in settings.py to "localhost". If it doesn't work, try "127.0.0.1". This is typically caused by the python-mysql module expecting the mysql unix socket to be in another place than it is. Actually, I'm unsure if the mysql server uses a unix socket on Windows. Anyway, one of both should work :) You can use the credentials you use to login with phpmyAdmin also for Django. Many consider it bad style to use root for non-administration tasks (and I agree), but for starters and on your development machine it isn't too big of an issue. phpMyAdmin should work out of the box with your django-managed databases.

我的MySQL数据库settings.py块如下所示:

My database settings.py block for mysql looks something like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'DBNAME',                      # Or path to database file if using sqlite3.
        'USER': 'USER',                      # Not used with sqlite3.
        'PASSWORD': 'PASSWORD',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

这是针对django 1.2及更高版本.如果遇到问题,请分别用相应的值替换DBNAME,USER和PASSWORD,并尝试将"127.0.0.1"作为主机.显然,您需要像使用sqlite一样运行"manage.py syncdb",然后才能使用它.

This is for django 1.2 and above. Replace DBNAME, USER and PASSWORD with the respective values and try '127.0.0.1' as HOST if you run into problems. Obviously, you'd need to run 'manage.py syncdb' as you did with sqlite before you can use it.

这篇关于django,phpmyadmin和mysql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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