结果是类似这样的
代码语言:javascript复制[root@opti-slave tmp]# cat optimize.sql
optimize table azheng_db.answers;
optimize table azheng_db.feedbacks;
optimize table azheng_db.logged_exceptions;
optimize table azheng_db.question_answers;
optimize table azheng_db.questions;
optimize table azheng_db.rule_answers;
optimize table azheng_db.rule_feedbacks;
...
...
...
执行优化
代码语言:javascript复制[root@opti-slave hunter]# time nohup mysql -u root -p < optimize.sql 2>&1 >> optim.log
nohup: redirecting stderr to stdout
Enter password:
输入密码后,就开始了优化过程
可以另开一个终端进行监视
代码语言:javascript复制[root@opti-slave hunter]# tail -f optim.log
bat_db.spec_items optimize status OK
Table Op Msg_type Msg_text
...
...
...
也可以使用 show processlist 在数据库里查看当前状态
代码语言:javascript复制mysql> show processlist;
---- ------ ----------- ------ --------- ------ ------------------- ----------------------------------------- ----------- ---------------
| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined |
---- ------ ----------- ------ --------- ------ ------------------- ----------------------------------------- ----------- ---------------
| 24 | root | localhost | NULL | Query | 21 | copy to tmp table | optimize table func_db.sport_stat_items | 0 | 0 |
| 29 | root | localhost | NULL | Query | 0 | init | show processlist | 0 | 0 |
---- ------ ----------- ------ --------- ------ ------------------- ----------------------------------------- ----------- ---------------
2 rows in set (0.01 sec)
mysql>