我已经在XAMPP中运行了MySQL,我还安装了用于python的MySQLdb。然而,我无法找到一种使用XAMPP的MySQL用于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.
}
}我在用Django。如果我使用SQLite3而不是MySQL,它可以正常工作。但我想使用MySQL。
EDIT#1
MySQL正在使用端口:3306。我怎么才能让他们工作?
发布于 2012-12-20 11:57:05
经过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.
}
}在cmd:python manage.py runserver中运行命令,并打开网页。
发布于 2012-12-20 09:45:17
您能检查端口吗?因为mysql使用默认端口为3306 (如果不是手动更改的话)
发布于 2012-12-20 09:45:25
您很可能需要添加一个运行mysql的端口,这可能是xampp将mysql设置到另一个端口,而不是标准的3306。
你能在django之外连接到mysql吗?
我想,您应该在xampp目录中找到一些mysql.exe文件。如果您通过终端导航到该目录,然后运行mysql.exe -uroot -p。添加密码,这很可能是空白密码。
https://stackoverflow.com/questions/13969077
复制相似问题