0

In a Django project, we are having the same application in dev and in prod. The application runs in prod since three months now. I imported the database from this application with scp user@remote_host:remote_file local_file, and I would like to connected to my own application in dev. The backup file is called backup-credit24h-prod-2017-08-29.sql. How could I do it?

  • https://stackoverflow.com/questions/18284562/import-large-sql-file-django did you take a look at this? – Henry H Aug 29 '17 at 18:19
  • What DB are you using? If Mysql, input it in a console: `mysql -u root -p < backup-credit24h-prod-2017-08-29.sql` If it other DB there exist simmilar way – amarynets Aug 29 '17 at 18:20

1 Answers1

0

I dont know if my answer are inline with question but what I understand is how I can use prod database in dev. So here is the steps.

  1. Create a database with some name on dev machine, lets say it prod-backup
  2. Associate the newly created database to the existing db user. Doing so the existing db user will have full access to the database prod-backup.
  3. Import the sql file backup-credit24h-prod-2017-08-29.sql to database prod-backup Using db sql import command.
  4. Go to the django settings and change the db name. help
  5. Restart the web server.

Apart from that you can take a look on how to manage different settings targeting for dev/local etc. and prod without any interference. How to manage local vs production settings in Django?

Though you can import sql file in the existing db too but in that way you may break the some behaviour and that's why I took that approach. But you are free to import the sql file in the existing db too and in that case you do not have to follow above steps (Ensure you take current dev's db backup prior to running import command)

Overriding existing db. Open terminal and go to mysql console. help

  1. DROP DATABASE databasename;
  2. create database databasename;
  3. Log out from the mysql console and execute command #4
  4. mysql -u username -p databasename < backup-credit24h-prod-2017-08-29.sql.sql # Enter the password as prompted
MaNKuR
  • 2,578
  • 1
  • 19
  • 31
  • If you could associate the mysql command to each point, I will accept your answer. Just use simple mysql command please, it should work fine. –  Aug 29 '17 at 18:35