简体   繁体   English

从Arduino Yun执行MySQL脚本(没有Python)

[英]Execute MySQL script from Arduino Yun (without Python)

I want to retrieve data from MySQL database which is running directly in Arduino YUN itself. 我想从直接在Arduino YUN本身中运行的MySQL数据库中检索数据。 I want to do it without Python, but directly using MySQL commands and Process. 我想在没有Python的情况下做到这一点,而是直接使用MySQL命令和Process。 Is it possible? 可能吗?
Every post that I found in the internet is about to "how to retrieve data using python". 我在互联网上找到的每个帖子都将涉及“如何使用python检索数据”。 But I don't want to use python, because connecting do database and etc. routine slows down my queries. 但是我不想使用python,因为连接do database等例程会使我的查询变慢。
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. 因此,我将数据检索的逻辑移到了MySQL函数上,现在想只使用Process类来调用此函数。 The problem is that it works directly from mysql console, works using python, but doesn't work directly. 问题在于它可以直接在mysql控制台上运行,可以使用python来运行,但是不能直接运行。 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. 这段代码完美地使用了python。 Inside read.py file I have database call routine. 在read.py文件中,我具有数据库调用例程。 So I want to do the same thing, but without python: 所以我想做同样的事情,但是没有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. 但是,如果我通过控制台运行,则相同的Mysql脚本可以完美运行,并且比使用python快得多。

You can use subprocess module. 您可以使用subprocess模块。

https://docs.python.org/2/library/subprocess.html 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. 使用此方法,您可以将mysql命令发送到终端,就像直接通过python脚本发送一样。

Try Process.runShellCommand . 尝试使用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')\"");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM