0

I'm trying to make a python program which uses python to interact with MySQL. What I want to do is to have the program return and store into a variable the return of that command variable.

For example, if I entered into the MySQL command line SHOW tables;, it would show me all the tables, and it would look something like this:

+----------------+
| Tables_in_test |
+----------------+
| food           |
| games          |
| movies         |
+----------------+

I want to know if there's any way to get that output into, for instance, a variable in python.

Thanks!

1 Answer 1

0

Write a stored procedure where it uses the cursor.

cursor contains the rows of the command SHOW tables 

when you call the sp through your code[python] you can get the results

Sign up to request clarification or add additional context in comments.

4 Comments

What I want is for the program not requiring a previous knowledge of the tables in the database, but that it uses the result of the code and stores it in a variable.
unable to get what exactly u want to achieve, would u like to elaborate ?
I was a way to get the output of the console into a variable. For example, if I typed 'show tables;", the result of that would be put into a variable. That result would be the table shown above.
if i understood it correctly, you want the sql command output to be stored into a variable[pyhton] As i mentioned earlier, please look into the following items[select ..into , cursor, storedprocedure ] if that is not your requirement , then this might help you stackoverflow.com/questions/10070406/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.