Can not connect to remote MySQL DB from Django -


i having troubles connecting remote mysql server django. setup uses multiple databases:

databases = {     'default': {         'engine': 'django.db.backends.mysql', # add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.         'name': 'ldatabase',                      # or path database file if using sqlite3.         # following settings not used sqlite3:         'user': 'luser',         'password': 'lpass',         'host': '',                      # empty localhost through domain sockets or '127.0.0.1' localhost through tcp.         'port': '',                      # set empty string default.     },     'physics': {         'engine': 'django.db.backends.mysql', # add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.         'name': 'rdatabase',                      # or path database file if using sqlite3.         # following settings not used sqlite3:         'user': 'ruser',         'password': 'rpass',         'host': 'hostname',                      # empty localhost through domain sockets or '127.0.0.1' localhost through tcp.         'port': '3306',                      # set empty string default.     } } 

the default db running on localhost (aka client) machine , physics on remote server.

i can connect remote mysql server with:

> mysql -u ruser -prpass -h hostname welcome mysql monitor.  commands end ; or \g. mysql connection id 34714 server version: 5.5.29 mysql community server (gpl) ... 

or python

> python python 2.7.3 (default, aug  9 2012, 17:23:57)  [gcc 4.7.1 20120720 (red hat 4.7.1-5)] on linux2 ... >>> import mysqldb >>> con = mysqldb.connect(host='hostname', port=3306, user='ruser', passwd='rpass', db='rdatabase') >>> cursor = con.cursor() >>> cursor.execute('select * rdatabase.labs') 425l 

however connection django fails with:

exception value: (2003, "can't connect mysql server on 'hostname' (13)") 

in fact, i've tested setup on laptop: laptop client , remote mysql server has same settings. works fine.

please, issue have run out of ideas. maybe there kind of hidden django setting on client machine missing?

find client , server configurations below.

thanks.

client setup

> python python 2.7.3 (default, aug  9 2012, 17:23:57)  [gcc 4.7.1 20120720 (red hat 4.7.1-5)] on linux2 ...  > pip list django (1.5.1) mysql-python (1.2.4) ...  > uname --all linux <hostname> 3.8.9-200.fc18.x86_64 #1 smp fri apr 26 12:50:07 utc 2013 x86_64 x86_64 x86_64 gnu/linux  > mysql welcome mysql monitor.  commands end ; or \g. mysql connection id 31 server version: 5.5.31 mysql community server (gpl) 

server setup

> uname --all linux <hostname> 3.6.10-2.fc16.x86_64 #1 smp tue dec 11 18:55:03 utc 2012 x86_64 x86_64 x86_64 gnu/linux  > mysql welcome mysql monitor.  commands end ; or \g. mysql connection id 34712 server version: 5.5.29 mysql community server (gpl)  > cat /etc/mysql.cnf [mysqld] datadir =/var/lib/mysql socket  =/var/lib/mysql/mysql.sock #user   =mysql  # disabling symbolic-links recommended prevent assorted security risks symbolic-links=0 #default-character-set=utf8 max_allowed_packet = 1048576000 [mysqld_safe] log-error   =/var/log/mysqld.log pid-file    =/var/run/mysqld/mysqld.pid  [client] #default-character-set=utf8 

the problem selinux prevents apache scripts connect network db default in fedora 18 explained here:

weird mysql python mod_wsgi can't connect mysql server on 'localhost' (49) problem

the solution enable httpd_can_network_connect via:

sudo setsebool -p httpd_can_network_connect_db on 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -