LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can not get MySQL to work from a System call

Solved!
Go to solution

I am sorry, I don't know the answer...

 

What I would try is:

 

- LaunchExecutable ( "Mysql < USE MY_DATABASE" ); instead of FmtOut (“%S”, “USE MY_DATABASE\r\n”);

or alternatively:

- FakeKeystroke ( VAL_ENTER_VKEY );

0 Kudos
Message 11 of 20
(1,513 Views)

erdc3,

 

I'd suggest trying the suggestions to add the USE MY_DATABASE command to the LaunchExecutable call, or to try other methods of sending input to the console.

 

I'm thinking this might not be the easiest way to work with your database if you intend to do anything more complex than opening it. We do offer a CVI SQL Toolkit that provides commands for working with databases:

 

http://sine.ni.com/nips/cds/view/p/lang/en/nid/11128

 

Would it be possible to get a bit more information about what you're trying to do with the MySQL database? That might help us suggest the best approach.

 

In the meantime though, I'd definitely try adding the commands into the LaunchExecutable command. 

0 Kudos
Message 12 of 20
(1,500 Views)

Thanks Daniel-E for the reply. All I want to do is up load a CSV file to a data base. So all the code I would need to send to MySQL after loging in would be the following:

 

LOAD DATA INFILE 'c:\file.csv' INTO TABLE 'db.table'

FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'

0 Kudos
Message 13 of 20
(1,496 Views)

Just out of curiosity: What happens if you try

 

LaunchExecutable ( "Mysql < USE MY_DATABASE" );

 

as I suggested earlier?

0 Kudos
Message 14 of 20
(1,494 Views)

Sorry Wolfgang, I meant to respond to your input. But when I use

 

LaunchExecutable ( "Mysql < USE MY_DATABASE" );

 

It just throws back at me its help file list. 

0 Kudos
Message 15 of 20
(1,492 Views)

I don't have a MySQL server running here, so I cannot try it, but I remember that you can execute MySQL statements in a script file.

 

So may be placing all your SQL commands in that script file may work:  LaunchExecutable ( "mysql dbname < script.sql" ); could be that line feeds are interpreted differently if read from the script...? 

0 Kudos
Message 16 of 20
(1,489 Views)

Good call Wolfgang, but that just gives me the help list. For some reason it will only take the following command and respond to it:

 

LaunchExecutable ("Mysql –h localhost –u me –password=pw");

0 Kudos
Message 17 of 20
(1,486 Views)

erdc3,

 

I think it might be helpful to use the LaunchExecutable command in a way that emulates the Windows command line. Here's a page from the CVI Help about the LaunchExecutable command:

 

http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/libref/cvilaunchexecutable/

 

By inserting cmd.exe /c at the front of the string argument in your LaunchExecutable command, it will open cmd.exe (the Windows command line), and run the rest of the argument as an input to the command line. 

 

So I'm looking at some of the documentation for the MySQL command line tool, specifically this page: http://dev.mysql.com/doc/refman/5.5/en/batch-commands.html

 

It seems like you should be able to use a command similar to the following:

 

LaunchExecutable("cmd.exe /c mysql -h localhost -u me -password=pw <databaseFile.sql");

 

where "databaseFile.sql" is the text file containing your commands. The first line of this file might need to be a USE command to tell it which database to use--so if your database is my_database, you'd need to say USE my_database as the first line of your file.

 

Hopefully that will work for you--let us know!

 

Message 18 of 20
(1,474 Views)
Solution
Accepted by topic author erdc3

Thanks Daniel-E! that did the job. I can now up load the data from the Labwindows/CVI code and it does not show the logon/password needed to connect to the database.

0 Kudos
Message 19 of 20
(1,471 Views)

That's great to hear! Good luck with the project, and let us know if you have any more questions!

0 Kudos
Message 20 of 20
(1,465 Views)