python Fabric mysql 权限

标签 python string-formatting

尝试使用fabric设置mysql用户权限。

run("mysql -u %s -p%s -e 'grant all on %s.* to '%s'@'localhost' identified by 'PASSWORD'" % (user, dbpasswd, account))

错误

TypeError: not enough arguments for format string

有什么想法吗?非常感谢!

run('mysql -u %s -p%s -e "grant all on %s.* to '%s\'@\'localhost' identified by 'PASSWORD'"' % (user, dbpasswd, account, account))

SyntaxError: unexpected character after line continuation character

最佳答案

将您的元组更改为(user, dbpasswd, account, user),您应该可以了。发生此错误的原因是您有 4 个替换 token (%s),但元组中只有 3 个项目。

关于python Fabric mysql 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11392721/

相关文章:

java - 用Java压缩,用Python解压?

Python:在浮点到字符串转换中抑制指数格式(即9e-10)?

java - 逗号作为Java中的小数点分隔符

java - 从 S3 下载所有文件并将它们上传到同一文件夹中

python - exec()在函数python3.x中不起作用

python - 如何在我的代码周围包装 python 守护进程

python - Python 3 中的 XMPP 线程接收器

c# - ByteArray 的 String.Format 将 0x00 转换为 0,如何保留 00

c# - 从货币中删除小数

当字符串包含 "%s"而没有转义时的 Python 字符串格式