我们先直接看命令:

    1. #查询除config表外的所有表
    2. SELECT CONCAT('TRUNCATE ',`TABLE_NAME`,';')
    3. FROM `information_schema`.`TABLES`
    4. WHERE `TABLE_SCHEMA` = '数据库名称' AND `TABLE_NAME` NOT IN ('config');

    下面我们来试试看

    1. mysql> show tables;
    2. +----------------+
    3. | Tables_in_test |
    4. +----------------+
    5. | aaa |
    6. | bbb |
    7. | ccc |
    8. | config |
    9. +----------------+
    10. 4 rows in set (0.00 sec)
    11. mysql>

    可以看到 test 库有4张表,下面我们来拼接清空除 config 表外的所有表命令。

    1. mysql> SELECT CONCAT('TRUNCATE ',`TABLE_NAME`,';')
    2. -> FROM `information_schema`.`TABLES`
    3. -> WHERE `TABLE_SCHEMA` = 'test' AND `TABLE_NAME` NOT IN ('config');
    4. +--------------------------------------+
    5. | CONCAT('TRUNCATE ',`TABLE_NAME`,';') |
    6. +--------------------------------------+
    7. | TRUNCATE aaa; |
    8. | TRUNCATE bbb; |
    9. | TRUNCATE ccc; |
    10. +--------------------------------------+
    11. 3 rows in set (0.00 sec)
    12. mysql>

    怎么样,是不是很简单,直接复制下来就行了。