django settings.py syncdb ("Can't connect to MySQL server on (111)")

3.6k views Asked by At

I have some sipmlest settings with two servers. On first(192.168.250.199) I have django, and on another(192.168.250.200) i have a mysql server

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--                                                                                          
    }                                                                                                                         
}  

So I try to sync database by running '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)")

This error called 'Mysql Database Connection Refused' and i should looking for mysqld settings, BUT, if i trying to connect directly from console:

>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>

It sucesseffuly! In Django project no more specific settings, and it work normaly using local database (yes, i have tried to put local my.conf on remote server - no effect).

  • no selinux, iptables and other security stuff
  • using redhat likely OS (CentOS and Scientific Linux)

I hope I have described my problem well. Thanks.

1

There are 1 answers

0
Sudip Kafle On BEST ANSWER

I think there is a mistake in your port number. If you want to leave it to default please leave the field as blank. Verify that you are entering the correct port number.