简体   繁体   English

导出MySQL数据库使用python报错

[英]Exporting MySQL database using python error

I am exporting MySQL database using python using command我正在使用命令使用 python 导出 MySQL 数据库

import os
password = '1234'
os.system('mysqldump -u root -p%s ot_database > D:\\ot.sql' % password)

The code was executed with no errors and A ot.sql file is created but the file is empty There is no data in ot.sql代码执行没有错误,并且创建了ot.sql文件,但文件为空ot.sql中没有数据

Please find the bug.请找出错误。

After Lot of research and debugging Finally I found the answer.经过大量的研究和调试,终于找到了答案。 os.system execute command line commands on some default directory but mysqldump is available in some other directory so I must change the current directory to the directory where mysqldump is available using command..... os.system在一些默认目录上执行命令行命令,但mysqldump在其他一些目录中可用,因此我必须使用命令将当前目录更改为 mysqldump 可用的目录.....

mysqldump_dir = 'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\'
os.chdir(mysqldump_dir)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM