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!

JohnyNich
  • 1,221
  • 3
  • 14
  • 23

1 Answers1

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

Ampati Hareesh
  • 1,852
  • 1
  • 15
  • 20
  • 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. – JohnyNich Aug 14 '17 at 11:10
  • unable to get what exactly u want to achieve, would u like to elaborate ? – Ampati Hareesh Aug 14 '17 at 11:45
  • 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. – JohnyNich Aug 14 '17 at 11:50
  • 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 https://stackoverflow.com/questions/10070406/how-to-store-query-result-in-variable-using-mysql – Ampati Hareesh Aug 14 '17 at 17:10