Database Connectivity using MySQL

In this tutorial we will see how to open connection for database and the various methods for opening connection. Connection should be closed at the end.

Tools Required:

In LabVIEW functions palette, Database VI’s are located in Connectivity >>Database.

Turn ON the MySQL server in MySQL workbench if not running.

MySQL server

First step is to open Connection to the database by wiring connection information in   “DB Tools Open”. Input can be any of the following.

  • DSN name
  • Udl path
  • Connection string

Open Connection:

Connection Information input has to be given for “DB Tools Open”. DSN name, Connection String or Udl path can be given. Be careful when you give udl path when creating application. Below is an example which shows the possible inputs which can be given for opening connection.

Open Connection to db1

CREATE DSN [Data Source Name]:

    1. Create DSN by going to Control Panel -> Administrative Tools ->DataSources(ODBC)

Create DSN 1

    1. Click Add to create New User DSN [Specific to User whereas System DSN is for all users in that PC] which prompts a window to select a data source.


    1. Select Finish and configure ODBC by giving Data Source Name, TCP/IP Server [localhost-if the server is in same PC or else give ip address of MySQL server], user name, password and database name.



Click Test to test the connection. It will show connection successful message. Then Click OK.


Right click on windows and create new text document and save as MyUdl.udl

Open MyUdl.udl and select Provider.


Now configure for the connection.


And test the connection.


Connection string can be obtained by two ways. One is from udl file and the other from LabVIEW.

  1. Open Udl file, select Connection tab and select Connection string and click build. Select the DSN name under Machine Data Source tab and click OK.
  2. In LabVIEW,

Connection StringNOTE: Type select @@datadir; in MySQL command line client to know where the databases are stored.


Leave a Reply