ÊÖ°ÑÊÖ½ÌÄãʵÏÖMySQLË«»úÊý¾Ýͬ²½

·¢±íÓÚ£º2011-7-01 09:53

×ÖÌ壺´ó ÖРС | ÉÏһƪ | ÏÂһƪ | ÎÒҪͶ¸å

 ×÷ÕߣºÎ´Öª    À´Ô´£º51TestingÈí¼þ²âÊÔÍø²É±à

·ÖÏí£º
  1. root@test2 ~: mysql -u root -p  
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.   
  4. Your MySQL connection id is 2   
  5. Server version: 5.0.45 Source distribution   
  6.    
  7. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.   
  8.    
  9. mysql> create database foo ;  
  10. Query OK, 1 row affected (0.00 sec)   
  11. ###Ôö¼ÓÓû§ test123 ´ÓÈκÎÖ÷»úµÇ¼µ½ MySQL  
  12. mysql> grant all privileges on *.* to 'test123'@'%' identified by 'test123' with grant  option;   
  13. Query OK, 0 rows affected (0.00 sec)   
  14. ###Ôö¼ÓÓû§ test1 ´Ó 192.168.7.67 Ö÷»úµÇ¼µ½ MySQL  
  15. mysql> grant all privileges on foo.* to 'test1'@'192.168.7.67' identified by 'test1' with grant   option;   
  16. Query OK, 0 rows affected (0.00 sec)

¡¡¡¡Èç¹ûÓзÀ»ðǽµÄÉèÖõĻ°£¬¿ÉÒÔÈçÏÂÉèÖãº

  1. root@test2 ~: iptables -A INPUT -i eth0 -s 192.168.7.67 -p tcp --dport 3306 -j ACCEPT   
  2. root@test2~: /etc/init.d/iptales save

¡¡¡¡×îºóÔÚ¿Í»§¶Ë¾Í¿ÉÒÔÊäÈëÏÂÃæÃüÁîÀ´Ô¶³Ì½øÈë MySQL Êý¾Ý¿â£º

  1. jian.ma@camlit ~: mysql -u test1 -h 192.168.56.103 -p   
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.   
  4. Your MySQL connection id is 13   
  5. Server version: 5.0.45 Source distribution   
  6. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

¡¡¡¡mysqld.plÄÚÈÝÈçÏ£º

  1. #!/usr/bin/perl 
  2.  
  3. #This script is used to check if the mysql replication is ok 
  4.  
  5. use strict; 
  6. use DBI; 
  7. use POSIX "strftime"
  8.  
  9. my $host           = "192.168.56.103"
  10. my $user           = "test1"
  11. my $passwd         = "test1"
  12. my $port           = "3306"
  13. my $max_behind     = "120"
  14. my $check_log      = "./mysql_check.log"
  15.  
  16.  
  17. #Open the log file  
  18. open (FH, ">> $check_log"or die $!; 
  19.  
  20. #Connect the mysql server  
  21. my $dbh = &MysqlConnect ($host, $port, $user, $passwd); 
  22.  
  23.  
  24. #Get slave sql status 
  25. my $slave_status = &MysqlQuery( $dbh, 'show slave status'); 
  26. print FH "Error: SQL Query Error:" . $dbh->errstr; 
  27.  
  28.  
  29. my $slave_IO              = $slave_status->{Slave_IO_Running}; 
  30. my $slave_SQL             = $slave_status->{Slave_SQL_Running}; 
  31. my $seconds_behind_master = $slave_status->{Seconds_Behind_Master}; 
  32. my $now_time              = POSIX::strftime ("[%Y-%m-%d %H:%M:%S]", localtime); 
  33.  
  34.  
  35. print "Check the Slave MySQL stauts....\n"
  36. print "_" x 50"\n"
  37. print "Time:\t\t\t$now_time\n"
  38. print "Slave IO Running:\t\t$slave_IO\n"
  39. print "Slave SQL Running::\t\t$slave_SQL\n"
  40. print "Behind Master Seconds:\t\t$seconds_behind_master\n"
  41.  
  42.  
  43. if ($seconds_behind_master > $max_behind){ 
  44.     print "Slave SQL Server is far behind master "
  45.  
  46.  
  47. #---Functions----# 
  48. sub MysqlConnect  { 
  49.  
  50.     my ($host, $port, $user, $passwd) = @_; 
  51.     my $dsn  = "DBI:mysql:host=$host;port=$port"
  52.     return DBI->connect($dsn, $user, $passwd, {RaiseError => 1}); 
  53.  
  54.  
  55. sub MysqlQuery { 
  56.  
  57.     my ($dbh , $query) = @_; 
  58.     my $sth = $dbh->prepare($query); 
  59.     my $res = $sth->execute; 
  60.     return undef unless $res; 
  61.     my $row = $sth->fetchrow_hashref; 
  62.     $sth->finish; 
  63.     return $row; 
  64. }

44/4<1234
¼ÛÖµ398ÔªµÄ²âÊԿγÌÃâ·ÑÔùËÍ£¬ÌîÎʾíÁìÈ¡°É£¡

¹Ø×¢51Testing

ÁªÏµÎÒÃÇ

¿ì½ÝÃæ°å Õ¾µãµØͼ ÁªÏµÎÒÃÇ ¹ã¸æ·þÎñ ¹ØÓÚÎÒÃÇ Õ¾³¤Í³¼Æ

·¨ÂɹËÎÊ£ºÉϺ£äîϪÂÉʦÊÂÎñËù ÏîÆåÂÉʦ
°æȨËùÓÐ ÉϺ£²©Îª·åÈí¼þ¼¼Êõ¹É·ÝÓÐÏÞ¹«Ë¾ Copyright©51testing.com 2003-2022
ͶËß¼°Òâ¼û·´À¡£ºwebmaster@51testing.com; ÒµÎñÁªÏµ£ºservice@51testing.com 021-64471599-8017

»¦ICP±¸05003035ºÅ

»¦¹«Íø°²±¸ 31010102002173ºÅ