PHP / MySQL数据库优化功能

After frequent record deletion from your MySQL database tables, your tables can acquire overhead. Overhead is empty space left inside the database table due to the deletions. A great way to speed up your MySQL database, not to mention keep it compact, is to use a simple PHP function to optimize your database tables:

从MySQL数据库表中频繁删除记录后,您的表可能会增加开销。 开销是由于删除而在数据库表内留下的空白空间。 加速MySQL数据库(更不用说使其紧凑)的一种好方法是使用一个简单PHP函数来优化数据库表:

/*  OPTIMIZE ALL TABLES  */
function optimize_database($DATABASE_LINK) {
	$result = mysql_query('SHOW TABLES', $DATABASE_LINK) or die('Cannot get tables');
 	while($table = mysql_fetch_row($result)) {
		mysql_query('OPTIMIZE TABLE '.$table[0], $DATABASE_LINK) or die('Cannot optimize '.$table[0]);
	}
}

I use the $DATABASE_LINK variable to keep my connection throughout my PHP script. Obviously it's not required, so you can modify the above function if you don't keep that variable.

我使用$ DATABASE_LINK变量来保持整个PHP脚本的连接。 显然,这不是必需的,因此,如果不保留该变量,则可以修改上述函数。

翻译自: https://davidwalsh.name/php-mysql-database-optimization-function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值