Home >Database >Mysql Tutorial >Linux系统下MySQL用户限额的实现

Linux系统下MySQL用户限额的实现

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 16:51:131107browse

原理:由于Linux系统下MySQL每个用户的数据库都是以目录的形式存在于/var/db/mysql或者其他目录下。一个目录就是一个数据库。所以可以通过检

原理:
由于Linux系统下MySQL每个用户的数据库都是以目录的形式存在于/var/db/mysql或者其他目录下。

一个目录就是一个数据库。所以可以通过检测目录的大小得到数据库大小,判断容量是否超过限额,如果超过限额就取消该用户的insert,create,update,create temp table权限,,允许select,delete等其他权限。

实现的脚本如下:
su-2.05b# cat quotamysql.sh
#!/bin/sh
#hmy-2004-8-19 v-0.1

mysqldir=/usr/db/mysql
infofiledir=/root/hmywork
limitfile=limitmysql
userfile=user_mysql
#定义初始变量
while [ 1 ];
do
sleep 10
#每隔10秒检查一次

for i in `cat ${infofiledir}/${userfile}`
do
now=`du ${mysqldir}/$i |tail -n 1 |awk '{print $1}'`
#取得当前目录大小
limit=`grep $i ${infofiledir}/${limitfile}|awk '{print $2}'`
#取得限额大小
if [ "$now" -gt "$limit" ];
#如果大于限额就执行下面的mysql语句
then
mysql --user=MySql@AdminU_ser --password=***********update db set insert_priv='N' ,update_priv='N', create_priv='N',Create_tmp_table_priv='N' where db='$i';
flush privileges ;
EOF
echo $i database full! `date`>;>;fulluser
sed /`echo $i`/d $userfile >;tempfile
fi
done
cp tempfile $userfile

done

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn