1

我有两台服务器的一些最简单的设置。在第一个(192.168.250.199)我有 django,在另一个(192.168.250.200)我有一个 mysql 服务器

192.168.250.200:/etc/my.cnf

[mysqld]
#Base settings for mysql
datadir=/ext/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql

#Coding settings for databases
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
init-connect="SET NAMES utf8"
skip-character-set-client-handshake

#Connections and package settings
wait_timeout=600
max_allowed_packet=64M

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

192.168.250.199:/.../settings.py

DATABASES = {                                                                                                                 
   'default': {                                                                                                               
        'ENGINE': 'django.db.backends.mysql',                                                                                 
        'NAME'      : 'monika',#--a1--                                                                                        
        'USER'      : 'monika',#--a2--                                                                                        
        'PASSWORD'  : 'monika',#--a3--                                                                                        
        'HOST'      : '192.168.250.200',#--a4--                                                                                            
        'PORT'      : '3336',#--a5--                                                                                          
    }                                                                                                                         
}  

所以我尝试通过运行'python settings.py syncdb'来同步数据库

python manage.py syncdb

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 443,         in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 231, in execute
    self.validate()
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.6/site-packages/django/core/management/validation.py", line 103, in get_validation_errors
    connection.validation.validate_field(e, opts, f)
  File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
    db_version = self.connection.get_server_version()
  File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 415, in get_server_version
self.cursor().close()
  File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py", line 317, in cursor
cursor = self.make_debug_cursor(self._cursor())
  File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor
    self.connection = Database.connect(**kwargs)
  File "/usr/lib64/python2.6/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib64/python2.6/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 '192.168.250.200' (111)")

这个错误称为“Mysql 数据库连接被拒绝”,我应该寻找 mysqld 设置,但是,如果我尝试直接从控制台连接:

>mysql --host=192.168.250.200 --user=monika --password=monika --database=monika
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.0.77 Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

成功了!在 Django 项目中没有更具体的设置,它使用本地数据库正常工作(是的,我试图将本地 my.conf 放在远程服务器上 - 没有效果)。

  • 没有 selinux、iptables 和其他安全的东西
  • 使用 redhat 可能的操作系统(CentOS 和 Scientific Linux)

我希望我已经很好地描述了我的问题。谢谢。

4

1 回答 1

0

我认为您的端口号有误。如果您想将其保留为默认值,请将该字段留空。验证您输入的端口号是否正确。

于 2013-09-09T07:37:04.340 回答