[Solved] Restart Mysql by PHP [closed]


Yes, it is possible. How depends on which OS you’re running.
One approach is the PHP exec function to execute a external program.

The command to be executed depend on the OS, as I said. Here are the command (If I’m correct, please tell me if I’m not):

Debian / Ubuntu:

/etc/init.d/mysql restart

Mac OS X

/usr/local/mysql/support-files/mysql.server restart

Windows

net stop MySQL
net start MySQL

On Windows MySQL might vary. If this does not work for you take a look at this question:
restart mysql server on windows 7

Another approach might be through SSH using the SSH PHP extension, which needs to be installed first. Take a look at: http://www.php.net/manual/en/ssh2.installation.php

Then connect to the SSH server and execute the commands:

 $con = ssh2_connect("example.com", 22); // Connect to SSH server
 $exec = ssh2_exec($con, "/etc/init.d/mysql restart"); // Execute command 

Hope this is helped you out 😉

4

solved Restart Mysql by PHP [closed]