Forum Moderators: coopster

Message Too Old, No Replies

Using PHP's system() to restart MySQL

         

Gero_Master

9:14 am on Jul 17, 2006 (gmt 0)

10+ Year Member



I need to make a function that would allow me to easily restart my MySQL database on my machine that currently runs on Windows.

This is what I have done so far to restart the server:

<?php
if(system('shutdown -r -f -t 10 -c "Restarting the server within 10 seconds!"')) {
echo "Server restarting...";
} else {
echo "Server couldn't be restarted...";
}
?>

How do I need to change the code inside system() to make my function restart only the MySQL database?

My "server" has Windows XP and Xampp

RonPK

11:20 am on Jul 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're running MySQL as a service, the commands are amazingly simple:

system('net stop "MySQL"');
system('net start "MySQL"');

Otherwise, you need to call the appropiate executables in your mysql/bin folder. On my system:

system('"C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqladmin.exe" -u root -ppassword shutdown');
system('"C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqld_nt.exe"');

Note that there is no whitespace between -p and the password.

On my system, this shuts the mysql server down but fails to restart it - maybe because I installed it as a service.

Gero_Master

2:43 pm on Jul 17, 2006 (gmt 0)

10+ Year Member



Thanks!

Now I started to feel bit stupid as I have used "net stop" and "net start" many times with my server. hehheh :)