Execute MySQL script from Arduino Yun (without Python)

955 views Asked by At

I want to retrieve data from MySQL database which is running directly in Arduino YUN itself. I want to do it without Python, but directly using MySQL commands and Process. Is it possible?
Every post that I found in the internet is about to "how to retrieve data using python". But I don't want to use python, because connecting do database and etc. routine slows down my queries.
I'm retrieving data from database multiple times, and from different tables. So I moved logic of data retrieval to MySQL function, and now want to just call this function using Process class. The problem is that it works directly from mysql console, works using python, but doesn't work directly. When I say directly, I mean this:

Process process;
process.begin("python");
process.addParameter("/mnt/sda1/arduino/python/read.py");
process.addParameter(msg);
process.run();

This code works perfectly and uses python. Inside read.py file I have database call routine. So I want to do the same thing, but without python:

Process process;
process.begin("mysql");
process.addParameter("-u root -parduino --database arduino -e \"select process('my_text')\"");
process.run();

As you can understand, this code sample doesn't work. But same Mysql script works perfectly, and much faster than using python, if I run it through console.

2

There are 2 answers

0
Sam On BEST ANSWER

Try Process.runShellCommand. It will accept your complete statement as an argument:

Process process;
process.runShellCommand("mysql -u root -parduino --database arduino -e \"select process('my_text')\"");
0
vks On

You can use subprocess module.

https://docs.python.org/2/library/subprocess.html

Using this you can send your mysql commands to the terminal as if sending directly through python script.