Unable to Create MySQL Database With LabVIEW Database Connectivity Toolkit

Updated Jun 9, 2023

Reported In

Software

  • LabVIEW
  • Database Connectivity Toolkit

Other

  • MySQL

Issue Details

I need to be able to create a database programmatically from LabVIEW, but there is no VI to create a database in the Database Connectivity Toolkit. 

I can manually create a MySQL database outside of LabVIEW and then access that particular database, however this approach does not work for my application.
 

Solution

Even though there is no create database VI, you can use the DB Tools Execute Query VI to execute the "CREATE DATABASE db_name" MySQL command from LabVIEW.

You would need a valid connection to the MySQL driver to be able to run the query. Two methods that can be used for this are:
 
  • Using a System DSN:
1. While creating a System DSN in the OBDC Data Source Administrator, leave the Database field blank:
 
image.png
 
2. In LabVIEW, place the DB Tool Open Connection VI and enter the System DSN's name, created in the previous step, in the connection information terminal.
3. Use the DB Tools Execute Query VI to create the database.
image.png
 
  • Using a connection string:
1. Input an appropriate connection string in the connection information terminal, without specifying a database. For example:
Driver={MySQL ODBC 8.0 ANSI Driver}; Server=localhost; User=root; Password=admin;
2. Use the DB Tools Execute Query VI to create the database.
 
image.png

Additional Information

After creating the database, if further interaction with it is needed you can use the DB Tools Execute Query VI again, and run the "USE db_name" command. This will allow you to then use other VIs in the Database Connectivity Toolkit, such as the DB Tools Create Table VI , and modify the created database.