cronjob从一个数据库读取并写入其他 [英] cronjob reading from one database and writing to other

查看:274
本文介绍了cronjob从一个数据库读取并写入其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 server1上有 table1



每天晚上我必须运行一个cronjob,

a。)删除 table2 $ c> server2



b。)读取 table1 的所有内容c $ c> server1 并转储到server2的 table2 table1 table2 有相同的模式)。



有办法,我可以做为一个SQL脚本。现在,我使用python做了两个数据库连接,从一个读取内容,然后转储到另一个并作为cronjob运行。



db是mysql。



感谢

解决方案

SQL脚本只是为您提供在数据库服务器上执行的命令。你仍然需要一些东西来做服务器连接。 SQL不会这样做,这不是什么SQL意味着。



你需要使用客户端,mysql / python或任何适合你。我建议你不要不必要地使事情复杂化。你现在正在做的似乎很好。


I have a table1 on server1

Every night I have to run a cronjob that would

a.) delete all contents of table2 on server2

b.) read all contents of table1 from server1 and dump it on table2 of server2 (table1 and table2 have same schemas).

Is there a way, I can do both as a SQL script. Right now, I am using python to make two database connections, read content from one and then dump into the other and running that as a cronjob.

The db is mysql.

Thanks

解决方案

In short, no. SQL script would just provide you with commans to execute on the database server. You still need something to make server connections. SQL wont do that for you, that's not what SQL is meant for.

You'll need to use a client, mysql/python or whatever suits you. I'd suggest you to not complicate matters unnecessarily. What you're doing right now seems fine.

这篇关于cronjob从一个数据库读取并写入其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆