在dev的数据库上连接prod的数据库

时间:2021-01-03 23:03:35

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?

在Django项目中,我们在dev和prod中拥有相同的应用程序。该应用程序自三个月后开始运行。我用scp user @ remote_host:remote_file local_file从这个应用程序导入了数据库,我想在dev中连接到我自己的应用程序。备份文件名为backup-credit24h-prod-2017-08-29.sql。我怎么能这样做?

1 个解决方案

#1


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.

我不知道我的答案是否与问题内联,但我理解的是如何在开发中使用prod数据库。所以这是步骤。

  1. Create a database with some name on dev machine, lets say it prod-backup
  2. 在dev机器上创建一个带有某个名称的数据库,让我们说它是prod-backup

  3. 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.
  4. 将新创建的数据库与现有数据库用户相关联。这样做,现有的db用户将拥有对数据库prod-backup的完全访问权限。

  5. Import the sql file backup-credit24h-prod-2017-08-29.sql to database prod-backup Using db sql import command.
  6. 使用db sql import命令将sql文件backup-credit24h-prod-2017-08-29.sql导入数据库prod-backup。

  7. Go to the django settings and change the db name. help
  8. 转到django设置并更改数据库名称。帮帮我

  9. Restart the web server.
  10. 重新启动Web服务器。

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?

除此之外,您还可以了解如何管理针对dev / local等的不同设置,并且不受任何干扰。如何在Django中管理本地vs生产设置?

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)

虽然您也可以在现有数据库中导入sql文件,但这样您可能会破坏某些行为,这就是我采用这种方法的原因。但您也可以*地导入现有数据库中的sql文件,在这种情况下,您不必执行上述步骤(确保在运行import命令之前获取当前dev的db备份)

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

覆盖现有数据库。打开终端并转到mysql控制台。帮帮我

  1. DROP DATABASE databasename;
  2. DROP DATABASE databasename;

  3. create database databasename;
  4. create database databasename;

  5. Log out from the mysql console and execute command #4
  6. 从mysql控制台注销并执行命令#4

  7. mysql -u username -p databasename < backup-credit24h-prod-2017-08-29.sql.sql # Enter the password as prompted
  8. mysql -u username -p databasename #输入提示密码

#1


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.

我不知道我的答案是否与问题内联,但我理解的是如何在开发中使用prod数据库。所以这是步骤。

  1. Create a database with some name on dev machine, lets say it prod-backup
  2. 在dev机器上创建一个带有某个名称的数据库,让我们说它是prod-backup

  3. 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.
  4. 将新创建的数据库与现有数据库用户相关联。这样做,现有的db用户将拥有对数据库prod-backup的完全访问权限。

  5. Import the sql file backup-credit24h-prod-2017-08-29.sql to database prod-backup Using db sql import command.
  6. 使用db sql import命令将sql文件backup-credit24h-prod-2017-08-29.sql导入数据库prod-backup。

  7. Go to the django settings and change the db name. help
  8. 转到django设置并更改数据库名称。帮帮我

  9. Restart the web server.
  10. 重新启动Web服务器。

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?

除此之外,您还可以了解如何管理针对dev / local等的不同设置,并且不受任何干扰。如何在Django中管理本地vs生产设置?

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)

虽然您也可以在现有数据库中导入sql文件,但这样您可能会破坏某些行为,这就是我采用这种方法的原因。但您也可以*地导入现有数据库中的sql文件,在这种情况下,您不必执行上述步骤(确保在运行import命令之前获取当前dev的db备份)

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

覆盖现有数据库。打开终端并转到mysql控制台。帮帮我

  1. DROP DATABASE databasename;
  2. DROP DATABASE databasename;

  3. create database databasename;
  4. create database databasename;

  5. Log out from the mysql console and execute command #4
  6. 从mysql控制台注销并执行命令#4

  7. mysql -u username -p databasename < backup-credit24h-prod-2017-08-29.sql.sql # Enter the password as prompted
  8. mysql -u username -p databasename #输入提示密码