脚本如下:
###begin srcript --author pat.dong####
# 如果用户空间超过,此文件将会作为邮件的内容发送到用户信箱
sizeover="/etc/sizeover.log"
dblist="/tmp/dblist"
mysql_path=/usr/local/mysql/bin
# 将数据库名称输出
$mysql_path/mysql -uroot -e "show databases">$dblist
# 删除第一栏 "Database"
sed 1d $dblist >/tmp/tmp123456
cat /tmp/tmp123456 >$dblist
# 数据库的数据路径
DB_PATH="/www/mysql"
# 用户所能使用的最大空间 单位 kb
LIMIT_SIZE=2048
#mysql_quota文件记录每个数据库的配额,内容如下:
####mysql_quota file begin######
cn-ce 10000
cnmr 2048
fulin 2048
ishunde 2048
jljust 15000
####end mysql_quota#####
# mysql 这个数据库不必改
cat $dblist | while read bdo
if [ $b != "mysql" ] &&[ -d $DB_PATH/$b ]
then
SIZE=`du $DB_PATH/$b -sk|awk {'print $1'}`
LIMIT_SIZE=`cat quota |grep $b|awk {'print $2'}`
echo "User Size is "$SIZE",Limt Size is "$LIMIT_SIZE
if [ $SIZE -gt $LIMIT_SIZE ]
then
# mysql -uroot -prootpwd -n -e "revoke insert on $b.* from $b@hostname"
# sendmail $b@mail.com <$sizeover
echo $b" is over quota"
else
# mysql -uroot -prootpwd -n -e "grant insert on $b.* to $b@hostname"
echo $b" is no over quota"
fi
# mysql -uroot -prootpwd -n -e "flush privileges"
fi
done
####end script#####
在phpmyadmin中点击数据库,在显示表的下方有统计容量大小的数据。例如:
columns_priv 0 MyISAM utf8_bin 1.0 KB -
db 1 MyISAM utf8_bin 4.9 KB 438 字节
func 0 MyISAM utf8_bin 1.0 KB -
help_category36 MyISAM utf8_general_ci 23.4 KB -
help_keyword 378 MyISAM utf8_general_ci 87.7 KB -
help_relation 724 MyISAM utf8_general_ci 18.4 KB -
help_topic 458 MyISAM utf8_general_ci 258.4 KB -
host 0 MyISAM utf8_bin 1.0 KB -
proc 0 MyISAM utf8_general_ci 1.0 KB -
procs_priv 0 MyISAM utf8_bin 1.0 KB -
tables_priv 0 MyISAM utf8_bin 1.0 KB -
time_zone 0 MyISAM utf8_general_ci 1.0 KB -
time_zone_leap_second 0 MyISAM utf8_general_ci 1.0 KB -
time_zone_name0 MyISAM utf8_general_ci 1.0 KB -
time_zone_transition 0 MyISAM utf8_general_ci 1.0 KB -
time_zone_transition_type0 MyISAM utf8_general_ci 1.0 KB -
user 2 MyISAM utf8_bin 2.2 KB -
17 个表 总计 1,599 MyISAM gb2312_chinese_ci 406.0 KB 438 字节
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)