Error while executing mysql query - mysql_query.run

53 views
Skip to first unread message

varun bhatnagar

unread,
May 30, 2017, 6:10:04 AM5/30/17
to Salt-users
Hello,

I am trying to execute a mysql query using saltstack but I am running into error again and again.
I have a small table which looks like this:

mysql> describe first_table;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(100) | NO   |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

mysql> 

And it has below information:

mysql> select * from first_table;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | test_name |
|  2 | john      |
|  3 | bruce     |
+----+-----------+
3 rows in set (0.00 sec)

mysql>

Now, I am trying to get everything from "name" column (and this is how my state file looks like):
get_data:
  mysql_query.run:
    - database: stagingdb
    - query: "SELECT name FROM first_table"
    - output: "/tmp/create_second_table.txt"

but when I do that I run into the below error everytime:

salt:
----------
          ID: get_data
    Function: mysql_query.run
      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 1746, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1704, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/states/mysql_query.py", line 151, in run
                  query_result = __salt__['mysql.query'](database, query, **connection_args)
                File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 645, in query
                  affected = _execute(cur, query)
                File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 544, in _execute
                  return cur.execute(qry)
                File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 158, in execute
                  result = self._query(query)
                File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 308, in _query
                  conn.query(q)
                File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 820, in query
                  self._affected_rows = self._read_query_result(unbuffered=unbuffered)
                File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1002, in _read_query_result
                  result.read()
                File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1292, in read
                  self._read_result_packet(first_packet)
                File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1347, in _read_result_packet
                  self._read_rowdata_packet()
                File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1385, in _read_rowdata_packet
                  rows.append(self._read_row_from_packet(packet))
                File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1399, in _read_row_from_packet
                  data = converter(data)
              TypeError: 'list' object is not callable
     Started: 12:00:47.029416
    Duration: 18.837 ms
     Changes: 

But if I try to fetch the column with "id" it runs perfectly fine:

salt:
----------
          ID: get_data
    Function: mysql_query.run
      Result: True
     Comment: {'rows returned': 3, 'query time': {'raw': '0.00055', 'human': '0.5ms'}, 'columns': (u'id',), 'results': [{u'id': '1'}, {u'id': '2'}, {u'id': '3'}]}
     Started: 11:54:25.539578
    Duration: 12.997 ms
     Changes:   
              ----------
              query:
                  Executed. Output into /tmp/create_second_table.txt

Summary for salt
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:  12.997 ms

Can anyone please tell me what am I doing wrong here?

BR,
Varun

varun bhatnagar

unread,
Jun 1, 2017, 3:34:01 AM6/1/17
to Salt-users
Hi,

Can anyone please help me with this one?

BR,
Varun
Reply all
Reply to author
Forward
0 new messages