A机器和B机器上都跑有数据库服务,B机器上的数据库是从A机器上导过来的,现在线上程序连接A机器数据库时正常,连接B机器异常,初步怀疑是数据库导入时记录不完整造成的。数据库中一共有100个多表,不可能一一肉眼比对其值.于是想出了一个办法,通过脚本来比对其值
1)初步的整理
A机器:
- mysqlshow -uroot -p db_name --count >> a.txt
B机器:
- mysqlshow -uroot -p db_name --count >>b.txt
整理a.txt中内容部分如下:
- aaa 31 16
- gift_card_base_info 10 851
- gift_card_use_info 6 252
- ms_log 6 5827
- ms_users 7 548
- ms_users_friends 8 918
- sph_counter 2 1
- who_account_log 10 692650
- who_active 7 94
- who_active_vote 11 40
- who_ad 13 1
- who_ad_custom 7 0
- who_ad_position 6 0
- who_admin_action 3 113
- who_admin_log 5 423922
- who_admin_message 9 0
- who_admin_user 13 176
- who_adsense 3 0
- who_affiliate_log 8 6154
- who_agency 3 0
- who_area_region 3 1780
- who_article 13 1839
- who_article_cat 8 33
- who_attr_composit 3 450
- who_attribute 10 12
- who_auction_log 5 0
- who_auto_manage 4 0
- who_back_goods 8 0
- who_back_order 31 4
- who_bak 31 52
- who_bak1 31 21
- who_bak2 31 38
- who_bak3 31 51
- who_bak4 31 82
- who_bak5 31 39
- who_bonus_type 11 0
- who_booking_goods 15 292713
- …………………………………………………………………………………………………………………………………………………………………………………………………………
b.txt
- aaa 31 16
- gift_card_base_info 10 851
- gift_card_use_info 6 265
- ms_log 6 5827
- ms_users 7 548
- ms_users_friends 8 918
- sph_counter 2 1
- who_account_log 10 698600
- who_active 7 94
- who_active_vote 11 40
- who_ad 13 1
- who_ad_custom 7 0
- who_ad_position 6 0
- who_admin_action 3 113
- who_admin_log 5 430266
- who_admin_message 9 0
- who_admin_user 13 177
- who_adsense 3 0
- who_affiliate_log 8 6154
- who_agency 3 0
- who_area_region 3 1780
- who_article 13 1845
- who_article_cat 8 33
- who_attr_composit 3 450
- who_attribute 10 12
- who_auction_log 5 0
- who_auto_manage 4 0
- who_back_goods 8 0
- who_back_order 31 4
- who_bak 31 52
- who_bak1 31 21
- who_bak2 31 38
- who_bak3 31 51
- who_bak4 31 82
- who_bak5 31 39
- who_bonus_type 11 0
- who_booking_goods 15 292674
- …………………………………………………………………………………………………………………………………………………………………………………………………………
2)还是利用perl脚本来对比两个文件的值吧,方便
code:
- #!/usr/bin/perl -w
- use strict;
- my (%hashA,%hashB) = ();
- open my $file,'<','record_194.txt' or die "$!\n";
- while (<$file>) {
- chomp;
- my @arrayA = split /\s+/;
- $hashA{$arrayA[0]} = $arrayA[2];
- }
- close $file;
- open $file,'<','record_2.txt' or die "$!\n";
- while (<$file>) {
- chomp;
- my @arrayB = split /\s+/;
- $hashB{$arrayB[0]} = $arrayB[2];
- }
- close $file;
- foreach my $table (sort keys %hashA) {
- if (exists $hashB{$table}) {
- if ($hashA{$table} != $hashB{$table}) {
- print $table,"\n";
- }
- }
- }
运行即可