假如SQL文件位于D:\java\opensource\mysql\pet.sql;内容简单的为use menagerie;select * from pet;

    当连接mysql服务是:

    1. mysql> source D:/java/opensource/mysql/pet.sql;
    2. +----------+--------+---------+------+------------+------------+
    3. | name | owner | species | sex | birth | death |
    4. +----------+--------+---------+------+------------+------------+
    5. | Fluffy | Harold | cat | f | 1993-02-04 | NULL |
    6. | Claws | Gwen | cat | m | 1994-03-17 | NULL |
    7. | Buffy | Harold | dog | f | 1989-05-13 | NULL |
    8. | Fang | Benny | dog | m | 1990-08-27 | NULL |
    9. | Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
    10. | Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
    11. | Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
    12. | Slim | Benny | snake | m | 1996-04-29 | NULL |
    13. | Puffball | Diane | hamster | f | 1999-03-30 | NULL |
    14. +----------+--------+---------+------+------------+------------+
    15. 9 rows in set (0.00 sec)

    未连接mysql服务是:

    1. C:\Users\Zk_Fo>mysql -uroot -p < D:\java\opensource\mysql\pet.sql
    2. Enter password: ****
    3. name owner species sex birth death
    4. Fluffy Harold cat f 1993-02-04 NULL
    5. Claws Gwen cat m 1994-03-17 NULL
    6. Buffy Harold dog f 1989-05-13 NULL
    7. Fang Benny dog m 1990-08-27 NULL
    8. Bowser Diane dog m 1979-08-31 1995-07-29
    9. Chirpy Gwen bird f 1998-09-11 NULL
    10. Whistler Gwen bird NULL 1997-12-09 NULL
    11. Slim Benny snake m 1996-04-29 NULL
    12. Puffball Diane hamster f 1999-03-30 NULL
    13. C:\Users\Zk_Fo>

    也可以将结果定向输出到文本文件中

    1. C:\Users\Zk_Fo>mysql -uroot -p < D:\java\opensource\mysql\pet.sql >d:\java\opensource\mysql\pet_result.txt
    2. Enter password: ****
    3. C:\Users\Zk_Fo>