Implementation of MySQL user quota in Linux

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.