用PHP重启Mysql [英] Restart Mysql by PHP
问题描述
是否可以使用 PHP 重新启动 MySQL?
Is it possible to restart MySQL using PHP?
我有一个需要频繁重启 MySQL 的网站,因为它使用了大量资源.我在这个网站保存了很多网页的代码源(大约3000个),当我使用我的内部搜索表单时,他的工作很低,因为要分析的信息很多,所以搜索后我需要重新启动我的MySQL服务器.
I have a website which need to restart MySQL frequently because it use a lot of ressource. I have saved in this website the code source of a lot of webpage (about 3 000) and when I use my internal search form, he works lowely because there is a lot of informations to analyze, so after a search I need to restart my MySQL server.
源代码:
$sql = "SELECT * FROM site WHERE adresse LIKE ? || source LIKE ? ORDER BY ID DESC";
$requete = $bdd->prepare($sql);
$requete->execute(array("%".$_GET['recherche']."%", "%".$_GET['recherche']."%"));
exec
是否允许重启 MySQL 以及如何重启?
Does exec
allow to restart MySQL and how ?
推荐答案
是的,这是可能的.如何取决于您正在运行的操作系统.一种方法是使用 PHP exec 函数来执行外部程序.
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
在 Windows 上,MySQL 可能会有所不同.如果这对您不起作用,请查看以下问题:在 Windows 7 上重启 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
另一种方法可能是通过 SSH 使用 SSH PHP 扩展,该扩展需要先安装.看看:http://www.php.net/manual/en/ssh2.installation.php
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
然后连接到SSH服务器并执行命令:
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
希望这对你有帮助;)
这篇关于用PHP重启Mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!