2 つのサーバーでいくつかの sipmlest 設定があります。最初(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 らしい OS (CentOS および Scientific Linux) を使用する
私の問題をうまく説明できたことを願っています。ありがとう。