Using MySQL Connector/Python, you are calling a stored procedure which is also selecting data and you would like to fetch the rows of the result.
For this example we create a stored procedure which is executing
SHOW SLAVE STATUS.
```python cnx = mysql.connector.connect(user=’scott’, password=’tiger’, database=’mining’) cur = cnx.cursor() cur.execute(“DROP PROCEDURE IF EXISTS slave_status”) proc = “CREATE PROCEDURE slave_status () BEGIN SHOW SLAVE STATUS; END” cur.execute() cur.call(“slave_status”)
for result_cursor in cur.stored_results(): for row in result_cursor: print(row) ```
The result from the above would be:
$ python foo.py
Waiting for master to send event
stored_results() method of cursor object is retiring an iterator object which will go over the results proceeded after calling the stored procedure. Each result is actually a MySQLCursorBuffered object.
If you like to leave a comment, but don't like to use Disqus, please send an email instead. Comments by email might end up as a FAQ here under.