- 浏览: 1304669 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (351)
- Java General (37)
- .net General (2)
- Linux Toy (55)
- Oracle (81)
- Mysql (11)
- Programer Career (12)
- Oh, my living ! (2)
- Shell Script (8)
- Web Service (0)
- Linux Server (22)
- Php/Python/Perl (3P) (2)
- Javascript General (5)
- Saleforce Apex Dev (2)
- Web General (5)
- Xen & VM tech. (17)
- PSP (13)
- OpenSolaris (34)
- php (1)
- RAI/flex/action script (16)
- asterisk/CTI (7)
- 交互设计 (6)
- English (3)
- Lucene (1)
最新评论
-
GuolinLee:
markmark
JVM调优总结 -Xms -Xmx -Xmn -Xss -
di1984HIT:
写的太好啊。
JVM调优总结 -Xms -Xmx -Xmn -Xss -
javajdbc:
javajdbc 写道
JVM调优总结 -Xms -Xmx -Xmn -Xss -
javajdbc:
...
JVM调优总结 -Xms -Xmx -Xmn -Xss -
alvin198761:
非常感谢,国外的被封杀了,你这里还有一份
How to Convert An Image-Based Guest To An LVM-Based Guest
MySQL DBA scripts
The following various scripts as used for various different tasks when reviewing MySQL installations.
- Calculate Your MySQL Database Size
- Calculate Your Individual MySQL Schema Size
- Log various MySQL statistics
- Analyze MySQL statistics
-
Automated MySQL Installation
Calculate Your Total MySQL Database Size
I use the following SQL script as an audit of for each current MySQL Database Instance. You can use this for example on a daily basis to get an indication of the overall growth of your database.
This SQL uses the MySQL Information_schema that is available for MySQL Version 5.0 and higher.
For those using MySQL 4.x, using the CHECK TABLE STATUS for each schema and manually computing the same produces a similar result.Usage
$ wget http://ronaldbradford.com/mysql-dba/allschemas.sql $ mysql -u[user] -p -v -v -v < allschemas.sql
Output
The following as sample outputs from clients.
+--------------------+-----------------+-----------------+-----------------+--------+ | table_schema | total_mb | data_mb | index_mb | tables | +--------------------+-----------------+-----------------+-----------------+--------+ | xxxxxx_xxx | 993088.84375000 | 776273.18750000 | 216815.65625000 | 54 | | information_schema | 0.00390625 | 0.00000000 | 0.00390625 | 17 | +--------------------+-----------------+-----------------+-----------------+--------+ 2 rows in set (59.81 sec)
+----------------------------+----------------+----------------+---------------+--------+ | table_schema | total_mb | data_mb | index_mb | tables | +----------------------------+----------------+----------------+---------------+--------+ | xxxxxxx_xxx_xxxx_xxx | 45314.47730350 | 38458.88941288 | 6855.58789063 | 2359 | | xxxxxxx_xxx_xxxx_xxx | 28758.38682079 | 24461.27060986 | 4297.11621094 | 275 | | xxxxxxx_xxx_xxxx_xxx | 28732.41495800 | 24464.20304394 | 4268.21191406 | 368 | | xxxxxxx_xxx_xxxx_xxx | 24586.48277569 | 20941.44176006 | 3645.04101563 | 302 | | xxxxxxx_xxx_xxxx_xxx | 3128.63515377 | 2664.54726315 | 464.08789063 | 48 | | xxxxxxx_xxx_xxxx_xxx | 2865.36613274 | 2440.44328117 | 424.92285156 | 265 | | xxxxxxx_xxx_xxxx_xxx | 1635.16585350 | 1388.68831444 | 246.47753906 | 2034 | | xxxxxxx_xxx_xxxx_xxx | 1442.15766239 | 1231.41840458 | 210.73925781 | 17 | ... +----------------------------+----------------+----------------+---------------+--------+ 74 rows in set (20.56 sec)
Calculate Your Individual Schema Size
Usage
$ wget http://ronaldbradford.com/mysql-dba/perschema.sql $ mysql -u[user] -p -v -v -v [table-schema] < perschema.sql
Output
+------------------+--------+------------+------------+----------------+--------------+--------------+--------------+ | table_name | engine | row_format | table_rows | avg_row_length | total_mb | data_mb | index_mb | +------------------+--------+------------+------------+----------------+--------------+--------------+--------------+ | xxxxxxx | InnoDB | Compact | 1778523 | 314 | 658.39062500 | 533.84375000 | 124.54687500 | | xxxxxxxxx | InnoDB | Compact | 553266 | 846 | 472.25000000 | 446.75000000 | 25.50000000 | | xxxxxxx | InnoDB | Compact | 435892 | 884 | 392.25000000 | 367.81250000 | 24.43750000 | | xxxxxxxxxxxxxx | InnoDB | Compact | 1106547 | 65 | 133.26562500 | 68.59375000 | 64.67187500 | | xxxxxxxxxxxxxxxx | InnoDB | Compact | 58281 | 531 | 30.34375000 | 29.51562500 | 0.82812500 | | xxxxxxxxxx | InnoDB | Compact | 68721 | 298 | 28.12500000 | 19.54687500 | 8.57812500 | ...
NOTE: The table_rows and corresponding avg_row_length is only approximate for Innodb tables. These values under certain circumstances can be wildly inaccurate. The data and index size are considered very accurate.
Logging MySQL Stats
Usage
$ wget http://ronaldbradford.com/mysql-dba/log-mysql-stats.sh $ chmod +x log-mysql-stats.sh $ export LOG_DIR=`pwd` $ export MYSQL_AUTHENTICATION="-umonitor -psakila" $ ./log-mysql-stats.sh variables $ ./log-mysql-stats.sh status $ ./log-mysql-stats.sh processlist $ ./log-mysql-stats.sh innodbstatus $ ./log-mysql-stats.sh masterstatus $ ./log-mysql-stats.sh slavestatus
Output
$ more mysql.variables.090629.003542.txt | date_time | 090629.003542 | | timezone | -0400 | +---------------------------------+-----------------------------------------------------------+ | Variable_name | Value | +---------------------------------+-----------------------------------------------------------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | ON | | automatic_sp_privileges | ON | | back_log | 50 | | basedir | /opt/mysql-5.1.25-rc-linux-x86_64-glibc23/ | | big_tables | OFF | | binlog_cache_size | 32768 | | binlog_format | MIXED | | bulk_insert_buffer_size | 8388608 | ...
$ more mysql.status.090629.003747.txt | date_time | 090629.003747 | | timezone | -0400 | +-----------------------------------+-------------+ | Variable_name | Value | +-----------------------------------+-------------+ | Aborted_clients | 4 | | Aborted_connects | 6037 | | Binlog_cache_disk_use | 0 | | Binlog_cache_use | 0 | | Bytes_received | 2303295323 | | Bytes_sent | 50239245119 | | Com_admin_commands | 0 | | Com_assign_to_keycache | 0 | | Com_alter_db | 0 | | Com_alter_db_upgrade | 0 | | Com_alter_event | 0 | | Com_alter_function | 0 | | Com_alter_procedure | 0 | | Com_alter_server | 0 | | Com_alter_table | 59 | | Com_alter_tablespace | 0 | ...
To implement logging in the real world.
Installationsudo su - useradd -m -s /bin/bash monitor mkdir /home/monitor/scripts cd /home/monitor/scripts wget http://ronaldbradford.com/mysql-dba/log-mysql-stats.sh chmod +x log-mysql-stats.sh mkdir -p /somedir/mysqlstatlogs chown monitor:monitor /somedir/mysqlstatlogs chown -R monitor:monitor /home/monitor
Configurationsu - monitor # -c Create Necessary MySQL Permissions # -u User with SUPER permissions, defaults to root scripts/log-mysql-stats.sh -udba -c
Testingmkdir tmp LOG_DIR=tmp scripts/log-mysql-stats.sh -m all ls -l tmp rm -rf tmp
Operation# m h dom mon dow command * * * * * LOG_DIR="/somedir/mysqlstatlogs" /home/monitor/scripts/log-mysql-stats.sh -m -l status innodbstatus masterstatus slavestatus 0 * * * * LOG_DIR="/somedir/mysqlstatlogs" /home/monitor/scripts/log-mysql-stats.sh -m -l processlist 0 0 * * * LOG_DIR="/somedir/mysqlstatlogs" /home/monitor/scripts/log-mysql-stats.sh -m -l variables 0 0 * * * LOG_DIR="/somedir/mysqlstatlogs" /home/monitor/scripts/log-mysql-stats.sh -z
Analyze MySQL statistics
$ wget -O mysql-stats.sh http://ronaldbradford.com/mysql-dba/mysql-stats.sh $ chmod +x mysql-stats.sh $ export LOG_DIR=`pwd` $ ./mysql-stats.sh all
Install MySQL
Usage
$ wget -O meta.sh http://ronaldbradford.com/mysql-dba/meta.sh $ wget -O install-mysql.sh http://ronaldbradford.com/mysql-dba/install-mysql.sh $ chmod +x ./install-mysql.sh $ sudo ./install-mysql.sh -d [/environment] [-i [ip-address]]
where:
- -d [/environment] is the base directory of the environment in question, for simplicity, use a base directory (e.g. from /) with the environment name. NOTE: Script is untested for directories that are not root level '/' directories.
- -i [ip] is a virtual IP that is assigned to the database environment
Pre-requisites
- This script must be run as the 'root' user, as it creates files and sets appropriate permissions.
- The base environment directory (e.g. /[environment]) must exist and be empty
- The Installed MySQL binary version must be in the /software directory
- The meta.sh file is required in the same directory as the install_mysql.sh file
Specific example
$ sudo su - $ mkdir /software /db1 $ cd /software $ wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.37-linux-x86_64-glibc23.tar.gz/from/http://mirror.trouble-free.net/mysql_mirror/ $ mkdir /db1 $ ./install-mysql.sh -d /db1
Example Output
# ./install-mysql.sh -d /db1 16:50:55 INFO Starting installation of MySQL 16:50:55 WARN IP not specified with -i, not binding to any IP 16:50:55 WARN No MySQL Version specified, using '5.1' 16:50:55 INFO Installing MySQL . . . 16:50:55 INFO Creating default MySQL user 16:50:55 INFO Group 'mysql' already exists 16:50:55 INFO User 'mysql' already exists 16:50:55 INFO Installing MySQL from binary tar file '/software/mysql-5.1.37-linux-x86_64-glibc23.tar.gz 16:51:03 INFO Setting MYSQL_HOME to '/db1/mysql' 16:51:03 INFO Installing mysql starter database 16:51:13 INFO Setting mysql directory ownership & permissions 16:51:13 INFO Configuring MySQL 16:51:13 INFO Setting MYSQL_HOME to '/db1/mysql' 16:51:13 INFO Generating my.cnf 16:51:13 INFO Configuring services for 'mysql_db1' 16:51:15 INFO Defining User Permissions 16:51:15 INFO Completed installation of MySQL
A successful installation will result in:- MySQL installed and running in /db1
$ export MYSQL_HOME=/db1/mysql $ $MYSQL_HOME/bin/mysql -udba -psakila -h${IP} -e "SELECT VERSION();SHOW SCHEMAS;" +------------+ | VERSION() | +------------+ | 5.1.37-log | +------------+ +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test_db1 | +--------------------+
Common Errors
Not run as root./install_mysql.sh 14:11:05 INFO Starting installation of MySQL 14:11:05 ERROR This script must be run as root 14:11:05 INFO Exiting with status code of '1'
Not specifying an environment directory with -d../install_mysql.sh 14:14:16 INFO Starting installation of MySQL 14:14:16 ERROR You must specify an install directory with -d 14:14:16 INFO Exiting with status code of '1'
Not specifying a binding IP Address with -i./install_mysql.sh -d /xxx 14:30:45 INFO Starting installation of MySQL 14:30:45 ERROR You must specify a binding IP with -i 14:30:45 INFO Exiting with status code of '1'
Specifying an environment directory that already contains an instance./install_mysql.sh -d /qa -i 192.168.1.22 14:33:33 INFO Starting installation of MySQL 14:33:33 WARN No MySQL Version specified, using '5.1' 14:33:33 ERROR A MySQL Instance at '/qa/mysql' has been detected, ensure no MySQL instance exists at '/qa' 14:33:33 INFO Exiting with status code of '1'
Specifying an environment directory that does not exist./install_mysql.sh -d /xxx -i 192.168.1.22 14:34:29 INFO Starting installation of MySQL 14:34:29 WARN No MySQL Version specified, using '5.1' 14:34:29 ERROR Base deployment directory '/xxx' does not exist 14:34:29 INFO Exiting with status code of '1'
Specify an invaid version of MySQL to install./install_mysql.sh -d /xxx -i 192.168.1.22 -v 5.2 14:37:34 INFO Starting installation of MySQL 14:37:34 ERROR Unable to find a '5.2' version of MySQL in '/software/' 14:37:34 INFO Exiting with status code of '1'
Unsupported Scripts
$ wget http://ronaldbradford.com/mysql-dba/mysql-sessions.sh
发表评论
-
A sample to update mysqm column charecter set
2010-10-21 12:58 1237mysql> SHOW CHARACTER SET LI ... -
使用MySQL的23个注意事项
2009-09-26 16:55 11361.如果客户端和服务器端的连接需要跨越并通过不可信任的网络,那 ... -
linux shell 下 用 mysql的中文问题
2009-09-18 10:30 2715虽然很少有人用linux下的mysql 客户端来维护数据,毕竟 ... -
Mysql Cluster: The definitive HOWTO
2008-07-29 14:55 1706Mysql Cluster: The definitive H ... -
mysql 打竖显示结果
2008-05-28 10:31 1492加个\G在最后现就可以了. mysql> select ... -
dump data into txt file
2008-05-10 15:42 1426mysql> select * from Directo ... -
Using Master/Slave Replication with ReplicationCon
2008-04-28 15:51 122325.4.4.6. Using Master/Slav ... -
How To Control Mysql Replication
2008-04-28 15:46 1629How To Control Mysql Replicatio ... -
Implementing High Availability in MySQL
2008-04-16 08:04 2317MySQL provides a built-in data ... -
innodb data file per table
2008-04-16 08:04 2104One very interesting thing I no ...
相关推荐
mysql dba 常用脚本 运行脚本可以方便管理MYSQL运行脚本可以方便管理MYSQL运行脚本可以方便管理MYSQL
该文档适合MYSQL数据库管理员使用,请大家多支持多指正
├─新版MySQL DBA 课件ppt │ 第一课数据库介绍篇.pdf │ 第七课MySQL数据库设计.pdf │ 第三十一课percona-toolkits 的实战及自动化.pdf │ 第三课MySQL授权认证.pdf │ 第九课MySQL字符集.pdf │ 第二十一课MySQL...
【No0230】姜承尧MYSQL DBA 44天视频课程【No0230】姜承尧MYSQL DBA 44天视频课程【No0230】姜承尧MYSQL DBA 44天视频课程【No0230】姜承尧MYSQL DBA 44天视频课程【No0230】姜承尧MYSQL DBA 44天视频课程【No0230】...
MySQL数据库巡检手册 MySQL DBA必备,建议下载参考学习
超经典MySQL DBA培训笔记
01 MySQL DBA基础.pdf 02 MySQL DBA安装.pdf 03 MySQL DBA基础操作.pdf 04 MySQL DBA视图操作.pdf 05 MySQL DBA索引管理.pdf 06 MySQL DBA安全权限.pdf 07 MySQL DBA日志管理.pdf 08 MySQL DBA备份恢复.pdf ...
MySQL DBA运维故障处理攻略 MySQL DBA运维故障处理攻略 MySQL DBA运维故障处理攻略
一共10套教程。深入浅出MySQL生产环境高可用架构MyCat教程 尚硅谷Redis视频 高性能mysql优化 打造扛得住的MySQL数据库架构(5.7 阿里大神讲授MySQL数据库运维(5.6) ...MYSQL运维DBA实战(5.5,一般,不推荐了)
MySQLDBA修炼之道-完整版,带书签,内容非常好。。。。。
姜承尧MYSQL DBA视频课程(44天全)高清视频教程下载
mysql DBA学习笔记
MySQL DBA之精通日志管理
MySQL DBA架构师学习笔记
超经典mysql dba 学习笔记
MySQL DBA面试题
3天入门MySQL DBA 想入门数据库学习的同学可以收走了。
MySql DBA 的方方面面,非常详细的英文资料