Django External DB Connection

Asked 2 years ago, Updated 2 years ago, 80 views

I want to operate the same server code shared by github on two different PCs (A, B). (For testing)

But I want to use DB only in A.

To import the DB of the APC as it is when you run the server from B to localhost

What kind of setting should I do in B?

At BPC settings.py

'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'server',  
    'USER': 'kim2',    
    'PASSWORD': 'kim2',  
    'HOST': 'A PC IP',          <<----------------------
    'PORT': ""
}

Stop the MySQL service on your BPC When I connected the Host to ACP, the server runs, but I can't access the actual DB

If you connect to localhost:8000/admin on the BPC,

OperationalError at /admin/ (2003, "Can't connect to MySQL server on 'localhost' (10061)")

The error is displayed.

Right-click MySQL in the bottom tray window on the APC It is marked as localhost (online), and SSH login-based management is not set separately in Remote Management. MySQL is serviced by default only.

I set up 3 things for external connection on A PC.

Create Account

create user 'kim2'@'%' identified by 'kim2';
grant all privileges on *.* to 'kim2'@'%';
flush privileges;

Port binding Firewall inbound/outbound 3306 ports allowed.

You set bind-address = 0.0.0.0 in the my.ini file.

From BPC

Mysql - h "A PC IP' -u root -p When connected, Could get value from table.

I think remote access is possible, but I can't access it from django server.

And I commited the source to Github after doing the following work in A.

And download the sauce from B

django database

2022-09-22 19:54

1 Answers

It's a self-answer...

I think there's a cache left because I kept running the server...

After restarting PaiCham, connecting to the server again

Data Sources and Drivers says it is connected to the IP of the APC.

I went to localhost:8000/admin and found out You're getting all the table values for A PC...

For testing purposes, follow the above settings.

We need to pay more attention to security in case of actual deployment.


2022-09-22 19:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.