mysql 监控脚本

mysql的空间使用脚本:

#!/bin/sh

#create by danchen
#2007-5-11
#function:mysql database schema tablespace

mysql -t -u root << EOF
SELECT a.schema_name db_name,
   IFNULL(ROUND((SUM(b.data_length)+SUM(b.index_length))/1024/1024,2),0.00)
total_size_mb,
   IFNULL(ROUND(((SUM(b.data_length)+SUM(b.index_length))-
   SUM(b.data_free))/1024/1024,2),0.00) data_used_mb,
   IFNULL(ROUND(SUM(data_free)/1024/1024,2),0.00) data_free_mb,
   IFNULL(ROUND((((SUM(b.data_length)+SUM(b.index_length))-SUM(b.data_free))/
   ((SUM(b.data_length)+SUM(b.index_length)))*100),2),0) pct_used,
   COUNT(table_name) tables
FROM information_schema.schemata a
LEFT JOIN information_schema.tables b ON a.schema_name = b.table_schema
WHERE a.schema_name != 'information_schema'
GROUP BY a.schema_name
ORDER BY 1;
exit
EOF


mysql的表分析脚本:

[mysql@test mysql]$ cat tabanalyze.sh
#!/bin/sh

#create by danchen
#2007-5-15
#function:produce analyze table syntax,this script is called by analyz.sh

mysql -u taobao <<EOF
use information_schema;
select concat('analyze table ',table_name,';') as head from tables where table_schema='email';
EOF

--------------------------------------------------------------------------------------------
[mysql@test mysql]$ cat analyze.sh
#!/bin/sh

#create by danchen
#2007-5-16
#function:analyze table and index

date
echo "analyze table begin"

#get all tables that need to analyze
/home/mysql/tabanalyze.sh > /tmp/table_analyze.sql
cat /tmp/table_analyze.sql|sed 's/head/use email;/' > /tmp/tmp_table_analyze.sql

#analyze
mysql -t -u taobao < /tmp/tmp_table_analyze.sql

echo "analyze table end"
date

你可能感兴趣的:(mysql)