我刚刚开始使用Python语言,并决定下载Django框架,我已经很好地工作了,但后来我尝试创建我的第一个"Django应用程序“( Django网站上的教程),当我遇到”数据库设置“时,我开始遇到使用Windows7的问题,在上传到服务器之前,我总是在WAMP中使用MySQL,所以我想我也可以在这里尝试一下,但我就是无法连接它,即使在像这样配置settings.py之后:
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'Python' # Or path to database file if using sqlite3.
DATABASE_USER = 'root' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = 'localhost' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.然后我下载并设法正确地安装了MySQLdb,所以我现在可以执行python导入MySQLdb了,但是我收到了这条消息,我真的不知道如何克服这个问题:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
362, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 195,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 221,
in execute
self.validate()
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 249,
in validate
num_errors = get_validation_errors(s, app)
File "C:\Python26\lib\site-packages\django\core\management\validation.py", lin
e 67, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "C:\Python26\lib\site-packages\django\db\backends\mysql\validation.py", l
ine 15, in validate_field
db_version = connection.get_server_version()
File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 29
7, in get_server_version
self.cursor()
File "C:\Python26\lib\site-packages\django\db\backends\__init__.py", line 81,
in cursor
cursor = self._cursor()
File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 28
1, in _cursor
self.connection = Database.connect(**kwargs)
File "C:\Python26\lib\site-packages\MySQLdb\__init__.py", line 75, in Connect
return Connection(*args, **kwargs)
File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 170, in __in
it__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'lo
calhost' (10061)")我应该仍然配置一些东西,还是我在某个时候配置错误了?此外,我也不能完全确定WAMP是否应该在这一点上运行=S,但我在Google上找不到任何关于我面临的问题。
发布于 2009-10-17 11:27:03
查看您安装MySQL的目录,可能类似于C:\Program Files\MySQL\MySQL Server 5.0。查看my.ini文件。检查服务器部分。它看起来像这样:
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306您使用的端口号是多少?好的,转到命令行并运行mysql:
C:\Users\foobar>mysql --port=3306 --user=root --password
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| proc |
| procs_priv |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
| user_info |
+---------------------------+
18 rows in set (0.00 sec)好的,那么你可以使用mysql了。进入你的Django local_settings.py并检查MySQL是否设置正确:
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'whatever'
DATABASE_USER = '<special app user>'
DATABASE_PASSWORD = '<password for user>'
DATABASE_HOST = '<ip address or host name of server>'
DATABASE_PORT = '3306'如果您从命令行执行了所有这些操作,则此Django设置将正常工作。
发布于 2009-10-17 03:02:56
我注意到的一件事是你的settings.py没有设置port #,它说它应该是默认的,但是tb没有提到默认的mysql端口是3306。也是在Windows上。如果您尚未验证连接参数,则应该验证服务器是否正在运行以及在哪个端口上运行。tb表示,它甚至找不到可以尝试连接的服务器。如果您安装了mysql客户端,请尝试使用正确的端口连接到它,以验证服务器是否在那里。或telnet 3306查看是否得到响应。
https://stackoverflow.com/questions/1580624
复制相似问题