- root@test2 ~: mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.0.45 Source distribution
-
- Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
-
- mysql> create database foo ;
- Query OK, 1 row affected (0.00 sec)
- ###Ôö¼ÓÓû§ test123 ´ÓÈκÎÖ÷»úµÇ¼µ½ MySQL
- mysql> grant all privileges on *.* to 'test123'@'%' identified by 'test123' with grant option;
- Query OK, 0 rows affected (0.00 sec)
- ###Ôö¼ÓÓû§ test1 ´Ó 192.168.7.67 Ö÷»úµÇ¼µ½ MySQL
- mysql> grant all privileges on foo.* to 'test1'@'192.168.7.67' identified by 'test1' with grant option;
- Query OK, 0 rows affected (0.00 sec)
|
¡¡¡¡Èç¹ûÓзÀ»ðǽµÄÉèÖõĻ°£¬¿ÉÒÔÈçÏÂÉèÖãº
- root@test2 ~: iptables -A INPUT -i eth0 -s 192.168.7.67 -p tcp
- root@test2~: /etc/init.d/iptales save
|
¡¡¡¡×îºóÔÚ¿Í»§¶Ë¾Í¿ÉÒÔÊäÈëÏÂÃæÃüÁîÀ´Ô¶³Ì½øÈë MySQL Êý¾Ý¿â£º
- jian.ma@camlit ~: mysql -u test1 -h 192.168.56.103 -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 13
- Server version: 5.0.45 Source distribution
- Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
|
¡¡¡¡mysqld.plÄÚÈÝÈçÏ£º
-
-
-
-
- use strict;
- use DBI;
- use POSIX "strftime";
-
- my $host = "192.168.56.103";
- my $user = "test1";
- my $passwd = "test1";
- my $port = "3306";
- my $max_behind = "120";
- my $check_log = "./mysql_check.log";
-
-
-
- open (FH, ">> $check_log") or die $!;
-
-
- my $dbh = &MysqlConnect ($host, $port, $user, $passwd);
-
-
-
- my $slave_status = &MysqlQuery( $dbh, 'show slave status');
- print FH "Error: SQL Query Error:" . $dbh->errstr;
-
-
- my $slave_IO = $slave_status->{Slave_IO_Running};
- my $slave_SQL = $slave_status->{Slave_SQL_Running};
- my $seconds_behind_master = $slave_status->{Seconds_Behind_Master};
- my $now_time = POSIX::strftime ("[%Y-%m-%d %H:%M:%S]", localtime);
-
-
- print "Check the Slave MySQL stauts....\n";
- print "_" x 50, "\n";
- print "Time:\t\t\t$now_time\n";
- print "Slave IO Running:\t\t$slave_IO\n";
- print "Slave SQL Running::\t\t$slave_SQL\n";
- print "Behind Master Seconds:\t\t$seconds_behind_master\n";
-
-
- if ($seconds_behind_master > $max_behind){
- print "Slave SQL Server is far behind master ";
- }
-
-
-
- sub MysqlConnect {
-
- my ($host, $port, $user, $passwd) = @_;
- my $dsn = "DBI:mysql:host=$host;port=$port";
- return DBI->connect($dsn, $user, $passwd, {RaiseError => 1});
- }
-
-
- sub MysqlQuery {
-
- my ($dbh , $query) = @_;
- my $sth = $dbh->prepare($query);
- my $res = $sth->execute;
- return undef unless $res;
- my $row = $sth->fetchrow_hashref;
- $sth->finish;
- return $row;
- }
|