*Note* In addition to this unsupported example, NI partner SAPHIR has released an officially supported toolkit called SmartSQLVIEW that enables connecting to mySQL databases directly from LabVIEW Real-Time targets such as CompactRIO and PXI. The toolkit features a simple API, utilities to help connect to a database and view tables, and documentation/support from SAPHIR. You can view additional information and purchase here (http://www.saphir.fr/GB/products/toolkits/SmartSQLVIEW_for_MySQL.html).
This example is a pure LabVIEW implementation to connect to a mySQL database (4.1 and later). Direct TCP/IP messages are sent and received from the example VI's and not through any abstraction layer such as ODBC. This example is meant for those needing to connect to a mySQL database from LabVIEW RT or other non-Windows platform (Linux, MacOS, touchpanel, PDA . . i.e. - any LabVIEW target with TCP/IP access). Those on Windows will find more stability and features with the LabVIEW Database Connectivity Toolkit which will allow connection to any database linked with Windows ODBC.
Steps to Complete
The attached zip file contains connect, query, and close methods. A basic example in included.
Minimal testing has been done with this example - please post bug corrections when found. This link provides the low level details for connecting to a mySQL database.
This example does not support encryption or compression on data sent to or received from the mySQL server and sets the appropriate connection flags so that the server will not send such messages.
For queries with no or small sets of returned data, expect 10-20% improvement in processing time over the LabVIEW Database Connectivity Toolkit since this example does not have the additional overhead of sending data through ODBC. However - large returned datasets will take significantly longer (10x+) than the LabVIEW Database Connectivity Toolkit. Memory is not preallocated for returned datasets and dynamically building large string arrays causes significant time with memory allocation. I have not had time to look into this and provide a good method - if anyone has good ideas or a solution your feedback is welcome.
The attached Code is provided As Is, subject to the Sample Code License Terms. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.