Django can simply connect to its MySQL server by setting HOST and PORT in settings.py as `` (empty line):
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'dbname', # Or path to database file if using sqlite3. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': 'root', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } }
My question is how to make it able to connect another database on a different host? Suppose my device is 192.168.1.33 and the other connected computer is 192.168.1.34 , both are on the same network. I tried to set this as:
'HOST': '192.168.1.34', 'PORT': '3306',
and
'HOST': '192.168.1.34', 'PORT': '',
but both raised this OperationalError :
(2003, "Can't connect to MySQL server on '192.168.1.34'(10061)")
SOLUTION: credit @cdhowie
Enter the address of the configuration binding to the host you want in /etc/mysql/my.cnf
Create a new user for the host you want to grant access to (if you do not have one).
Check privileges for this user (if access is denied).
Protocole
source share