Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get MySQL installation path

I need to get the installation path of MySQL in order to perform the export and import the database through java code. currently am working with eclipse. I need to get the installation path in a String variable "mySqlPath".

File fMysqlPath = new File("C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\");
String executeCmd = "mysqldump -u " + Constants.DB_USER + " -p" + 
                    Constants.DB_PASSWORD + " " + Constants.DB_NAME + " -r " + 
                    FilePath + "\\" + FileName;
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd, null, fMysqlPath);

This is what I have done. This has a dependency problem.

How can I solve this?

like image 408
Gapchoos Avatar asked Sep 27 '12 06:09

Gapchoos


1 Answers

You can directly query mysql and ask itself to give you the path:

SHOW VARIABLES LIKE 'basedir';

or the easier,

SELECT @@basedir;

Should give you the installation path. Both should result in something like:

C:\Program Files\MySQL\MySQL Server 5.1\

datadir is the equivalent to get path of the data directory (where the data lies).

like image 152
nawfal Avatar answered Sep 19 '22 12:09

nawfal