mysql user qutoa tool
#!/usr/bin/php -q
/*
* Create table for quota data with the following statement:
*
* CREATE TABLE `Quota` (`Db` CHAR(64) NOT NULL,
* `Limit` BIGINT NOT NULL,
* `Exceeded` ENUM('Y','N') DEFAULT 'N' NOT NULL,
* PRIMARY KEY (`Db`), UNIQUE (`Db`));
*
* The field 'db' stores the information for which database
* you want to limit the size.
* The field 'limit' is the size limit in bytes.
* The field 'exceeded' is only used internally and must be
* initialized with 'N'.
*/
/*
* Settings
*/
$mysql_host = 'localhost';
$mysql_user = 'root'; // Do NOT change, root-access is required
$mysql_pass = '';
$mysql_db = 'quotadb'; // Not the DB to check, but the db with the quota table
$mysql_table = 'quota';
/*
* MySQL quota script
* written by Sebastian Marsching
*
*/
* MySQL quota script
* written by Sebastian Marsching
*
*/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Create table for quota data with the following statement:
*
* CREATE TABLE `Quota` (`Db` CHAR(64) NOT NULL,
* `Limit` BIGINT NOT NULL,
* `Exceeded` ENUM('Y','N') DEFAULT 'N' NOT NULL,
* PRIMARY KEY (`Db`), UNIQUE (`Db`));
*
* The field 'db' stores the information for which database
* you want to limit the size.
* The field 'limit' is the size limit in bytes.
* The field 'exceeded' is only used internally and must be
* initialized with 'N'.
*/
/*
* Settings
*/
$mysql_host = 'localhost';
$mysql_user = 'root'; // Do NOT change, root-access is required
$mysql_pass = '';
$mysql_db = 'quotadb'; // Not the DB to check, but the db with the quota table
$mysql_table = 'quota';
/*
* Do NOT change anything below
*/
$debug = 0;
* Do NOT change anything below
*/
$debug = 0;
// Connect to MySQL Server
if (!mysql_connect($mysql_host, $mysql_user, $mysql_pass))
{
echo "Connection to MySQL-server failed!";
exit;
}
{
echo "Connection to MySQL-server failed!";
exit;
}
// Select database
if (!mysql_select_db($mysql_db))
{
echo "Selection of database $mysql_db failed!";
exit;
}
{
echo "Selection of database $mysql_db failed!";
exit;
}
// Check quota for each entry in quota table
$sql = "SELECT * FROM $mysql_table;";
$result = mysql_query($sql);
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$quota_db = $row['db'];
$quota_limit = $row['limit'];
$quota_exceeded = ($row['exceeded']=='Y') ? 1 : 0;
if ($debug)
echo "Checking quota for '$quota_db'...\n";
$qsql = "SHOW TABLE STATUS FROM $quota_db;";
$qresult = mysql_query($qsql);
if ($debug)
echo "SQL-query is \"$qsql\"\n";
$quota_size = 0;
while ($qrow = mysql_fetch_array($qresult))
{
if ($debug)
{ echo "Result of query:\n"; var_dump($qrow); }
$quota_size += $qrow['Data_length'] + $qrow['Index_length'];
}
if ($debug)
echo "Size is $quota_size bytes, limit is $quota_limit bytes\n";
if ($debug && $quota_exceeded)
echo "Quota is marked as exceeded.\n";
if ($debug && !$quota_exceeded)
echo "Quota is not marked as exceeded.\n";
if (($quota_size > $quota_limit) && !$quota_exceeded)
{
if ($debug)
echo "Locking database...\n";
// Save in quota table
$usql = "UPDATE $mysql_table SET exceeded='Y' WHERE db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
// Dismiss CREATE and INSERT privilege for database
mysql_select_db('mysql');
$usql = "UPDATE db SET Insert_priv='N', Create_priv='N' WHERE Db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
mysql_select_db($mysql_db);
}
if (($quota_size <= $quota_limit) && $quota_exceeded)
{
if ($debug)
echo "Unlocking database...\n";
// Save in quota table
$usql = "UPDATE $mysql_table SET exceeded='N' WHERE db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
// Grant CREATE and INSERT privilege for database
mysql_select_db('mysql');
$usql = "UPDATE db SET Insert_priv='Y', Create_priv='Y' WHERE Db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
mysql_select_db($mysql_db);
}
}
{
$quota_db = $row['db'];
$quota_limit = $row['limit'];
$quota_exceeded = ($row['exceeded']=='Y') ? 1 : 0;
if ($debug)
echo "Checking quota for '$quota_db'...\n";
$qsql = "SHOW TABLE STATUS FROM $quota_db;";
$qresult = mysql_query($qsql);
if ($debug)
echo "SQL-query is \"$qsql\"\n";
$quota_size = 0;
while ($qrow = mysql_fetch_array($qresult))
{
if ($debug)
{ echo "Result of query:\n"; var_dump($qrow); }
$quota_size += $qrow['Data_length'] + $qrow['Index_length'];
}
if ($debug)
echo "Size is $quota_size bytes, limit is $quota_limit bytes\n";
if ($debug && $quota_exceeded)
echo "Quota is marked as exceeded.\n";
if ($debug && !$quota_exceeded)
echo "Quota is not marked as exceeded.\n";
if (($quota_size > $quota_limit) && !$quota_exceeded)
{
if ($debug)
echo "Locking database...\n";
// Save in quota table
$usql = "UPDATE $mysql_table SET exceeded='Y' WHERE db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
// Dismiss CREATE and INSERT privilege for database
mysql_select_db('mysql');
$usql = "UPDATE db SET Insert_priv='N', Create_priv='N' WHERE Db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
mysql_select_db($mysql_db);
}
if (($quota_size <= $quota_limit) && $quota_exceeded)
{
if ($debug)
echo "Unlocking database...\n";
// Save in quota table
$usql = "UPDATE $mysql_table SET exceeded='N' WHERE db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
// Grant CREATE and INSERT privilege for database
mysql_select_db('mysql');
$usql = "UPDATE db SET Insert_priv='Y', Create_priv='Y' WHERE Db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
mysql_select_db($mysql_db);
}
}
?>
?PHP>來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-719649/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP S/4HANA key user tool extensibility原理
- CMSEASY /lib/tool/front_class.php、/lib/default/user_act.php arbitrary user password reset vulnerabilityPHP
- 如何使用Key User Tool擴充套件SAP S/4HANA Fiori UI套件UI
- mysql中delete fro mysql.user where XX和drop user的不同MySqldelete
- @1-MYSQL當前使用者user()與current_user()MySql
- mysql5.5的一些函式_user()_current_user()MySql函式
- ubuntu mysql Access denied for user root@localhostUbuntuMySqllocalhost
- 解決mysql“Access denied for user 'root'@'localhost'”MySqllocalhost
- go tool pprofGo
- 常用sqltun toolSQL
- Tool-Navicat
- Tool-PostgresqlSQL
- 【MySQL】關於 unauthenticated user的哲學思考MySql
- SAP C4C 2102版本如何使用Key User Tool建立擴充套件欄位 - extension field套件
- Spring Tool SuiteSpringUI
- [譯]RSA Tool Help
- WebService 之 Restful ToolWebREST
- mysql 1045, "Access denied for user 'root'@'localhost' (using password: NO)"MySqllocalhost
- Mysql 5.7 CentOS Access denied for user 'root'@'localhost'解決方式MySqlCentOSlocalhost
- Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost'MySqlErrorlocalhost
- mysql can't connect error about privilege----not root userMySqlError
- 解決mysql"Access denied fot user 'root'@'localhost'"問題MySqllocalhost
- Oracle Orion Calibration ToolOracle
- MYSQL解決error: 'Access denied for user 'root'@'localhost' (using password:MySqlErrorlocalhost
- mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解決方法MySql
- mysql ERROR 1045 (28000): Access denied for user解決方法MySqlError
- mysql.user表的資料準確性問題MySql
- [Tool] Git 使用 與 Git FlowGit
- Use Excel Pivot Table as a BI toolExcel
- jar-The Java Archive Tool (轉)JARJavaHive
- MySQL系列:Docker安裝 MySQL提示錯誤:Access denied for user'root'@'localhost' (using password:yes)MySqlDockerlocalhost
- ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'ErrorlocalhostDatabaseMySql
- 【MySQL】---1045-Access denied for user 'root'@'localhost'(using password :YES)MySqllocalhost
- 解決Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'MySqlErrorlocalhost
- Spring tool suite修改字型大小SpringUI
- online web design toolWeb
- Spring Tool Suite 3.0釋出SpringUI
- 【BATCH】BOESDK-Upload Deploy ToolBAT