xan*_*xan 4 python mysql django xampp mysql-python
我已经通过XAMPP运行MySQL了,我还安装了用于安装python的MySQLdb.然而,我无法弄清楚如何使用我的XAMPP的MySQL for Python.每次执行python manage.py runserver它都会显示错误:
..2.4c1-py2.7-win32.egg.tmp\MySQLdb\connections.py", line 187, in __init__
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
我是Python的新手,这些是settings.py文件中的设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'tester', # Or path to database file if using sqlite3.
'USER': 'root', # 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.
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Django.如果我使用SQLite3而不是MySQL,它可以正常工作.但我想使用MySQL.
编辑#1
MySQL正在使用端口:3306.我如何让他们工作?
经过5-6个小时的尝试,我终于开始工作了.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'tester', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'password', # Not used with sqlite3.
'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
Run Code Online (Sandbox Code Playgroud)
在cmd:中运行命令python manage.py runserver,然后打开网页.
| 归档时间: |
|
| 查看次数: |
3827 次 |
| 最近记录: |