为了技术,我不会停下学习的脚步,我相信我还能走二十年。
分类:
2012-07-24 16:17:59
mk-slave-find - 顾名思义,根据master查找slave。安装方法查看。
在mysql5.1里查看一个master有哪些slave可以通过PROCESSLIST系统表查出:
mysql> select HOST from information_schema.PROCESSLIST where STATE like '%slave%'; +------------------+ | HOST | +------------------+ | 192.168.1.2:44846 | | 192.168.1.3:33022 | | 192.168.1.4:50836 | | 192.168.1.5:32769 | | 192.168.1.6:33113 | | 192.168.1.7:33005 | | 192.168.1.8:32786 | | 192.168.1.9:32862 | +------------------+ 11 rows in set (0.00 sec)
在5.1之前想查出有哪些slave比较麻烦,比较直接的就是直接通过show processlist把所有进程列出,在去刷选查出:
show processlist; +-----------+----------+------------------+-----------+-------------+----------+----------------------------------------------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +-----------+----------+------------------+-----------+-------------+----------+----------------------------------------------------------------+------------------+ | 1211 | slave2 | 192.168.1.2:32807 | NULL | Binlog Dump | 10366310 | Has sent all binlog to slave; waiting for binlog to be updated | NULL | | 209052219 | slave3 | 192.168.1.3:60924 | NULL | Binlog Dump | 4733312 | Has sent all binlog to slave; waiting for binlog to be updated | NULL | | 291690986 | slave4 | 192.168.1.4:46357 | NULL | Binlog Dump | 2061057 | Has sent all binlog to slave; waiting for binlog to be updated | NULL | | 291719840 | slave5 | 192.168.1.5:33221 | NULL | Binlog Dump | 2060248 | Has sent all binlog to slave; waiting for binlog to be updated | NULL | | 291809908 | slave6 | 192.168.1.6:38799 | NULL | Binlog Dump | 2057734 | Has sent all binlog to slave; waiting for binlog to be updated | NULL | | 345256247 | slave7 | 192.168.1.7:39452 | NULL | Binlog Dump | 323761 | Has sent all binlog to slave; waiting for binlog to be updated | NULL | | 347842030 | test | 192.168.1.22:55278 | test | Sleep | 6 | | NULL | | 348667710 | test | 192.168.1.33:56003 | test | Sleep | 6 | | NULL | | 353741496 | test | 192.168.1.26:48062 | test | Sleep | 0 |
看起来都乱,所以Maatkit提供了mk-slave-find工具来方便查询master的slave,使用非常简单:
[root@mysql ~]# mk-slave-find --host 192.168.1.1 -u -p 192.168.1.1 +- 192.168.1.2 +- 192.168.1.3 +- 192.168.1.4 +- 192.168.1.5 +- 192.168.1.6 +- 192.168.1.7 +- 192.168.1.8 +- 192.168.1.9
最后,我们在看下这个工具的帮助选项:
[root@mysql ~]# mk-slave-find --help mk-slave-find finds and prints a hierarchy tree of MySQL slaves. For more details, please use the --help option, or try 'perldoc /usr/bin/mk-slave-find' for complete documentation. Usage: /usr/bin/mk-slave-find [OPTIONS] MASTER-HOST Options: --ask-pass Prompt for a password when connecting to MySQL --charset -A Enables character set settings in Perl and MySQL --config Read this comma-separated list of config files; if specified, this must be the first option on the command line --database -D Database to use --defaults-file -F Only read mysql options from the given file --help Show a brief help message and exit --host -h Connect to host --password -p Password to use when connecting --port -P Port number to use for connection --recurse Number of levels to recurse in the hierarchy --set-vars Specify any variables you want to be set immediately after connecting to MySQL --socket -S Socket file to use for connection --user -u User for login if not current user --version Output version information and exit DSN syntax is key=value[,key=value...] Allowable DSN keys: KEY COPY MEANING === ==== ============================================= A yes Default character set D yes Database to use F yes Only read default options from the given file P yes Port number to use for connection S yes Socket file to use for connection h yes Connect to host p yes Password to use when connecting u yes User for login if not current user Options and values after processing arguments: --ask-pass FALSE --charset FALSE --config /etc/maatkit/maatkit.conf,/etc/maatkit/mk-slave-find.conf,/root/.maatkit.conf,/root/.mk-slave-find.conf --database FALSE --defaults-file (No value) --help TRUE --host (No value) --password (No value) --port (No value) --recurse FALSE --set-vars FALSE --socket (No value) --user (No value) --version FALSE