Victor Ikenna
Victor Ikenna

Reputation: 45

Start XAMPP mysql server with Java code

Need to start the MySQL service from XAMPP with Java Code.(Without manually using the XAMPP console to start it).

I know you could use:

Process process = Runtime.getRuntime().exec("net START MySQL");

To start the MySQL in windows. But it seems XAMPP has MySQL as a subprogram (If I am right).

Any advice please?

Upvotes: 2

Views: 3054

Answers (2)

faraz naeem
faraz naeem

Reputation: 121

This is the simple way get the path where your xampp server is install. Then simply write this command in you main class constructor

Process xamppProcess=Runtime.getRuntime().exec("Path\\xampp_start.exe");

After this command write this command to connect to your Mysql database also get the saved path of mysql from your computer

Process db=Runtime.getRuntime().exec("sqlpath\\mysqld.exe");

this is it hope it work for you!!!

Upvotes: 0

m4heshd
m4heshd

Reputation: 970

This depends on the path where you have installed XAMPP. You can set MySQL server as an Autostart module in the XAMPP and then you can run

(Assuming you having XAMPP installed in default path)

Process process = Runtime.getRuntime().exec("C:\\xampp\\xampp_start.exe");

This may not be the easiest way but this will work. But also you should know that mysql is stored separately in XAMPP path as in C:\xampp\mysql\bin. So you can also run

Process process = Runtime.getRuntime().exec("C:\\xampp\\mysql\\bin\\mysqld.exe");

Hope this will help you.

Upvotes: 3

Related Questions