我可以: 邀请好友来看>>
ZOL星空(中国) > 技术星空(中国) > MySQL星空(中国) > (转载)Using INFORMATION_SCHEMA instead of shell scripting
帖子很冷清,卤煮很失落!求安慰
返回列表
签到
手机签到经验翻倍!
快来扫一扫!

(转载)Using INFORMATION_SCHEMA instead of shell scripting

52浏览 / 3回复

190
精华
190
帖子

等  级:Lv.1
经  验:40
  • Z金豆:

    千万礼品等你来兑哦~快点击这里兑换吧~

  • 城  市:
  • 注  册:
  • 登  录:
发表于 2008-12-25 09:04:07
电梯直达 确定
楼主
INFORMATION_SCHEMA, in particular by favorite TABLES table is not only helpful to understand tables you have on the
system, but I have also found it to be very helpful as a scripqing language for variety of databbse administration tasks. It can be more straightforward compared to using shell or Perl when the operation is databbse specific.For example if you would like to MySQLDump only Innodb table in one file per databbse you can do the following:mysql> SELECT concat("mysqldump ",table_schema," ",table_name, ">> ",table_schema,".sql")
       ->  FROM TABLES WHERE engine='innodb' LIMIT 5;
+------------------------------------------------------------------------------+
| concat("mysqldump ",table_schema," ",table_name, ">> ",table_schema,".sql") |
+------------------------------------------------------------------------------+
| mysqldump art73 article73>> art73.sql                                       |
| mysqldump art73 author73>> art73.sql                                        |
| mysqldump art73 forum73>> art73.sql                                         |
| mysqldump art73 forum_stats73>> art73.sql                                   |
| mysqldump art73 img_out73>> art73.sql                                       |
+------------------------------------------------------------------------------+
5 rows IN SET (48.69 sec)
As you can see we're just getting the set of commands to run. How to make it easily runable ? Well just use INTO OUTFILE to create very simple shell scripq:mysql> SELECT concat("mysqldump ",table_schema," ",table_name, ">> ",table_schema,".sql")
       ->  FROM TABLES WHERE engine='innodb' INTO OUTFILE '/tmp/dump.sh';
Query OK, 328 rows affected (46.88 sec)
In other case I needed to restore Innodb tables from mysqldump because of corrupted Innodb tablespace - to do this I had to clean all .frm files which correspond to innodb tables (as well as ibdata1 and innodb log files). With shell you could so it by looking for .frm files which do not have corresponding .MYI files.... but this will also get all MEMORY tables which we want to leave in tact. Using similar approach we can do:mysql> SELECT concat("rm -f /var/lib/mysql/",table_schema,"/",table_name, ".frm")
       ->  FROM TABLES WHERE engine='innodb' LIMIT 5;
+---------------------------------------------------------------------+
| concat("rm -f /var/lib/mysql/",table_schema,"/",table_name, ".frm") |
+---------------------------------------------------------------------+
| rm -f /var/lib/mysql/art73/article73.frm                            |
| rm -f /var/lib/mysql/art73/author73.frm                             |
| rm -f /var/lib/mysql/art73/forum73.frm                              |
| rm -f /var/lib/mysql/art73/forum_stats73.frm                        |
| rm -f /var/lib/mysql/art73/img_out73.frm                            |
+---------------------------------------------------------------------+
5 rows IN SET (44.68 sec Do not get me wrong, this is far from replacement for shell in all cases but it is rather handy for some niche tasks, in particular which involve unix commands driven by MySQL meta data.

3kpp

3kpp


精华

帖子

等  级:Lv.4
经  验:2862
发表于 2008-12-25 09:04:07 1楼
TKS

sariny

sariny


精华

帖子

等  级:Lv.7
经  验:14613
发表于 2008-12-29 15:21:43 2楼
information_schema的使用还是要慎重,因为information_schema的使用 也是建立在即时统计的基础上,也会带来很重的io负载.

sariny

sariny


精华

帖子

等  级:Lv.7
经  验:14613
发表于 2008-12-29 15:22:07 3楼
这种io负载对于某些高并发的服务器来说,可能就是致命的
高级模式
星空(中国)精选大家都在看24小时热帖7天热帖大家都在问最新回答

针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员查看帮助  或  给我提意见

快捷回复 APP下载 返回列表