pt-show-grants-飞外

只读工具和写工具pt-show-grants默认是只读,风险低。如果使用--flush,将执行flush privileges。至今没有已知bug导致用户的损失。pt-show-grants提取、排序和打印MySQL 相关账户存在的原因:1、从一台服务器上将权限复制到另一台机器上;可以很简单地从第一台服务器上抽取相关权限,然后直接导入第二台机器上;2、将权限信息放在版本控制中。使用自动grant dump到版本控制中,可能会获得一些没有变化的授权。原因在于mysql按照看似随机的顺序打印授权信息。一天打印如下:另一天可能打印:授权没变,但是顺序变了该脚本可以解决该问题,在GRANT和ON之间做排序。如果show grants结果存在多行的话,也会这些行进行排序。3、比较服务器之间的权限,没有规范化的,这样的操作会比较困难。输出结果完全是可对比的。执行pt-show-grans的过程:pt-show-grants -u pt -p 213456 -S ./tmp/mysql.sock全日志:从全日志中可以看到:1、先查找所有用户和Host2、然后逐个执行show grants两种不同的方式进行连接--ask-pass Prompt for a password when connecting to MySQL--ask-pass 作为密码的提示 在系统中运行出错出错信息:Enter password: Cannot read response; is Term::ReadKey installed? Can't locate Term/ReadKey.pm in @INC缺少Term/ReadKey.pm这个模块——在自己测试机上继续练习--charset=s -A Default character set--charset=s -A 连接使用的字符集pt-show-grants -upt -hlocalhost -S ./tmp/mysql.sock -p 213456 -A utf8对应的全日志中多了,37 Query /*!40101 SET NAMES utf8*/--config=A Read this comma-separated list of config files; if specified, this must be the first option on the command line--config类型为数组从特定的文件中读取配置,如果设置,这个选项需要设置在第一行--database=s -D The database to use for the connection--database=s -D 连接数据库使用到的DB--defaults-file=s -F Only read mysql options from the given filept-show-grants --defaults-file=./etc/my.cnf -upt -p213456--drop Add DROP USER before each user in the output添加了两行:DROP USER 'pt'@'%';
DELETE FROM `mysql`.`user` WHERE `User`='pt' AND `Host`='%';--flush Add FLUSH PRIVILEGES after output在输出最后一行加了如下一行命令:FLUSH PRIVILEGES;--[no]header Print dump header (default yes)--help Show help and exit--host=s -h Connect to host--ignore=a Ignore this comma-separated list of users【不起作用??】参数必须是'root'@'localhost',而不是root--only=a Only show grants for this comma-separated list of users只显示的用户--password=s -p Password to use when connecting--pid=s Create the given PID file--port=i -P Port number to use for connection--revoke Add REVOKE statements for each GRANT statement是REVOKE形式,与drop不同,其是delete--separate List each GRANT or REVOKE separately--set-vars=s Set these MySQL variables (default wait_timeout=10000)用法:--set-vars wait_timeout=100--socket=s -S Socket file to use for connection--[no]timestamp Add timestamp to the dump header (default yes)是否添加时间戳--user=s -u User for login if not current user--version Show version and exit选项类型:Option types: s=string, i=integer, f=float, h/H/a/A=comma-separated list, d=DSN, z=size, m=times表示stringi表示整数f表示浮点数h/H/a/A 表是逗号分隔型取值格式d表示DSNz表示大小m表示time参数的默认值:参数的默认值使用PTDEBUG可以将debug信息打印到STDERR,也可以重定向到文件中