Principle: in Linux, each user's database in MySQL is stored in a directory in vardbmysql or another directory. A directory is a database. So you can pass the check
Principle: in Linux, each user's database in MySQL is stored in/var/db/mysql or another directory. A directory is a database. So you can pass the check
Principle:
In Linux, MySQL Databases belong to/var/db/mysql or other directories.
A directory is a database. Therefore, you can obtain the database size by checking the directory size to determine whether the capacity has exceeded the limit. If the limit is exceeded, the insert, create, update, and create temp table permissions of the user are canceled, and select is allowed, delete and other permissions.
The implementation script is as follows:
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
# Defining initial variables
While [1];
Do
Sleep 10
# Check every 10 seconds
For I in 'cat $ {infofiledir}/$ {userfile }'
Do
Now = 'du $ {mysqldir}/$ I | tail-n 1 | awk '{print $1 }''
# Obtain the current directory size
Limit = 'grep $ I $ {infofiledir}/$ {limitfile} | awk '{print $2 }''
# Obtain the quota size
If ["$ now"-gt "$ limit"];
# If the limit is exceeded, execute the following mysql statement
Then
Mysql -- user = MySql @ AdminU_ser -- password = ************ <use mysql
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