数据库运维常用命令

来源:互联网 发布:关闭多台linux系统脚本 编辑:程序博客网 时间:2024/05/01 05:00

 1、导出非分区表数据
mysql.local -BNe 'show databases;' | egrep -v "[0-9]|mysql|monitor|test|information" | while read i ; do mysql.local -BNe "show tables in $i;"| grep -v [0-9] | while read j; do echo "mysqldump --defaults-file=/home/mysql/mysql/etc/user.root.cnf --single-transaction --default-character-set=latin1" $i $j ">" "$i.$j.sql"; done ; done

2、检验alter操作
awk '{print $3}' alter_trans_goods_channel.sql | while read i; do mysql.local -e "show create table $i\G" | grep -c F_goods_channel ;done | grep -v 2

3、观察机器剩余流量
fsh "`cat oldslave`" "grep -v Connect /home/noah/mysql_monitor/log/processlist.20130606 | egrep -v 'handoff|root|admin|rd' | awk '{print \$2\$3 \$4}' | sort -nu "

4、观察select流量的连接者
grep -i select mysql.log | egrep -v "version_comment|CREATE|INSERT" | awk '{print $3}' | sort -nu | grep -v select | while read i; do grep $i mysql.log | head -n 1; done

5、查看当前进程
fsh "`cat oldslave`" "whoami | xargs pstree"

6、校验数据:
cd log;
for i in *.checksum; do cat $i >>sum_check.log ; done ; md5sum sum_check.log

7、杀sleep链接:
mysql.local -NBe "show processlist;" | grep Sleep | grep -v system | awk '{print $1,$6}' | while read i j ;do if [ $j -gt 9 ];then mysql.local -e "kill $i";fi;done

8、导出表结构:
/home/mysql/mysql_cif/bin/mysqldump --defaults-extra-file=/home/mysql/mysql_cif/etc/user.root.cnf --single-transaction --default-character-set=latin1 -A -d -r pay-cif.sql

9、
START SLAVE UNTIL MASTER_LOG_FILE = 'mysql-bin.000105', MASTER_LOG_POS = 338801330;

10、统计当前连接情况
mysql.local -BNe "show processlist" | egrep -v "root|rep|mysqlsync" |awk '{split($3,array,":"); print $2 " " array[1]}' | sort | uniq -c | sort -rnk 1

11、统计某类分表的行数
1)mysql.mis -BNe "show databases like 'bfb_db_pas_%'" | while read i; do mysql.mis -BNe "use $i;show tables like 't_pa_account_single%'" | xargs -i /home/mysql/mysql_misc/bin/mysql --defaults-extra-file=/home/mysql/mysql_misc/etc/user.admin.cnf -BNe "select count(*) from $i.{}"; done | grep -n -v 0

2)mysql.mis -BNe " select TABLE_ROWS from information_schema.TABLES where TABLE_NAME like 't_pa_account_single%'" | sort -nr | uniq -c

12、查看binlog大小
du -csh mysql-bin.000*

13、导出数据字典:格式(database table colum)
mysql.cif -BNe "show databases"|grep -Evi "information_schema|mysql|dba|monitor|_[1-9][0-9]" | egrep -vi "_0[1-9]" | while read f; do mysql.cif $f -BNe "show tables" | while read k; do mysql.cif $f -BNe "show create table $k\G"| egrep -vi "CREATE TABLE|key|ENGINE=|.row |^t_"|awk '{print "'$f'","'$k'", $1}' | tr -d '`'; done; done > cif.sql

14、raid 参数查看
MegaCli -LDInfo -Lall -aALL | grep 'RAID Level:'
MegaCli -PDList -aALL | grep 'Firmware state:'
MegaCli -pdlist -aall | grep rror
MegaCli -adpallinfo -a0 | head -10