我正在使用 Python Sh ( https://amoffat.github.io/sh/ ),我想知道是否可以使用 <>
还有管道吗?
主要是说mysql < dump.sql
。
我正在考虑使用 mysql -D db -e "source mydump.sql'
但是source
不建议这样做。
还有其他选择吗?
最佳答案
您可以引用文档的 STDIN 处理 ( http://amoffat.github.io/sh/#stdin-processing ) 和重定向 ( http://amoffat.github.io/sh/#redirection ) 部分。也就是说,您的代码:
mysql < dump.sql
应该相当于:
dump_file = open("home/user/dump.sql", "r")
sh.mysql(_in=dump_file)
dump_file.close()
关于使用输出重定向 (<) 管道进行 MySQL 转储导入的 Python Sh 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28485994/