我需要测试一个使用mysql的django应用程序,所以我安装了portable-xampp并加载了数据库,但是我无法用django访问它。它在我使用远程数据库时有效,但在本地无效。用户、密码和数据库都可以,我也尝试使用 root,只是为了测试目的有什么想法吗?
在 settings.py 中:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'awe_db', # Or path to database file if using sqlite3.
'USER': 'awe_db', # Not used with sqlite3.
'PASSWORD': 'mypwd', # 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.
}
}
错误:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2.6.1\helpers\pycharm\django_manage.py", line 21, in <module>
run_module(manage_file, None, '__main__', True)
File "C:\Python27\lib\runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\Fernando Alves\Dropbox\Projetos\nova_b2blue\manage.py", line 14, in <module>
execute_manager(settings)
File "C:\Python27\Lib\site-packages\django\core\management\__init__.py", line 459, in execute_manager
utility.execute()
File "C:\Python27\Lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 231, in execute
self.validate()
File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\Lib\site-packages\django\core\management\validation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "C:\Python27\Lib\site-packages\django\db\backends\mysql\validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "C:\Python27\Lib\site-packages\django\db\backends\mysql\base.py", line 415, in get_server_version
self.cursor().close()
File "C:\Python27\Lib\site-packages\django\db\backends\__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Python27\Lib\site-packages\django\db\backends\mysql\base.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "C:\Python27\Lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\Lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")