django, phpmyadmin and mysql?(django、phpmyadmin 和 mysql?)
问题描述
我想开始使用 Django 和 MYSQL,而不是一直使用 sqlite,但是我使用 MSQL 的唯一经验是通过 XAMPP,通过 phpmyadmin 操作数据库.我真的很想保持这个 gui 与 mysql 的交互,而不必通过命令行来做所有的事情.
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数据库,然后web开发端用django只用django的sn开发服务器?
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"作为 HOST.显然,您需要像使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:django、phpmyadmin 和 mysql?
基础教程推荐
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01