且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Python 中使用 mysqldump 和 mysql 复制数据库?

更新时间:2023-02-02 22:11:44

我不知道你想复制的pure Python程度,但是你可以委托整个管道对 shell 的操作.

I don't know the degree of pure Python you want to use for the copy, but you can just delegate the entire pipe operation to the shell.

subprocess.Popen('mysqldump -h localhost -P 3306 -u -root mydb | mysql -h localhost -P 3306 -u root mydb2', shell=True)

这应该与您在 shell 上运行时的工作方式相同.

This should work the same way it works when you run it on the shell.