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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With