How to copy a database with mysqldump and mysql in Python?

后端 未结 3 590
名媛妹妹
名媛妹妹 2021-01-03 05:07

I am writing a simple Python script to copy a MySQL database. I am attempting to copy the database based on the following SO questions and their answers: \"Copy/duplicate da

3条回答
  •  粉色の甜心
    2021-01-03 05:57

    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)
    

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

提交回复
热议问题