盐栈mysql_grants.present下划线通配符

盐栈mysql_grants.present下划线通配符,mysql,salt-stack,Mysql,Salt Stack,我正在使用Salt来配置云服务器,但是我在MySQLdb为MySQL生成正确的权限时遇到了问题。如果我直接执行SQL,它将是: GRANT ALL ON `install\_%`.* TO 'installer'@'localhost'; sls文件包含: installer_local_install_grants: mysql_grants.present: - grant: all privileges - database: install\_%.* - u

我正在使用Salt来配置云服务器,但是我在MySQLdb为MySQL生成正确的权限时遇到了问题。如果我直接执行SQL,它将是:

GRANT ALL ON `install\_%`.* TO 'installer'@'localhost';
sls文件包含:

installer_local_install_grants:
  mysql_grants.present:
    - grant: all privileges
    - database: install\_%.*
    - user: installer
    - host: localhost
    - escape: False
这将产生以下错误:

    Function: mysql_grants.present
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1560, in call
              **cdata['kwargs'])
            File "/usr/lib/python2.7/dist-packages/salt/states/mysql_grants.py", line 187, in present
              grant, database, user, host, grant_option, escape, ssl_option, **connection_args
            File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 1666, in grant_add
              _execute(cur, qry['qry'], qry['args'])
            File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 505, in _execute
              return cur.execute(qry, args)
            File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 159, in execute
              query = query % db.literal(args)
          TypeError: * wants int
在提交给MySQLdb之前,在salt中启用debug的相关行是:

Doing query: GRANT ALL PRIVILEGES ON install\_%.* TO %(user)s@%(host)s args: {'host': 'localhost', 'user': 'installer'} 
因此,Salt似乎输出了正确的代码,但MySQLdb没有正确处理查询的某些部分。查询缺少背面的记号,但我真的不确定如何将它们输入

移除转义或将其设置为True后,授权看起来如下所示:

+-----------+-----------------+------------------+
| Host      | Db              | User             |
+-----------+-----------------+------------------+
| localhost | install\\_\%    | installer        |
+-----------+-----------------+------------------+
+-----------+-----------------+------------------+
| Host      | Db              | User             |
+-----------+-----------------+------------------+
| localhost | install\_%      | installer        |
+-----------+-----------------+------------------+
当它看起来像:

+-----------+-----------------+------------------+
| Host      | Db              | User             |
+-----------+-----------------+------------------+
| localhost | install\\_\%    | installer        |
+-----------+-----------------+------------------+
+-----------+-----------------+------------------+
| Host      | Db              | User             |
+-----------+-----------------+------------------+
| localhost | install\_%      | installer        |
+-----------+-----------------+------------------+

好的,你能打开一个引用此SO帖子的问题吗?谢谢


您是否尝试过在
install\\\\\%.*.
周围加上单引号?是的,我尝试过
'install\\\\\%.*.
并在DB名称周围加上双引号OK,所以可能不仅仅是我。我马上就开始讨论这个问题。谢谢