How to easily import multiple sql files into a MySQL database?

后端 未结 11 1893
一整个雨季
一整个雨季 2021-01-29 20:02

I have several sql files and I want to import all of them at once into a MySQL database.

I go to PHPMyAdmin, access the databa

11条回答
  •  半阙折子戏
    2021-01-29 20:12

    In Windows, open a terminal, go to the content folder and write:

    copy /b *.sql all_files.sql
    

    This concate all files in only one, making it really quick to import with PhpMyAdmin.

    In Linux and macOS, as @BlackCharly pointed out, this will do the trick:

    cat *.sql  > .all_files.sql
    

    Important Note: Doing it directly should go well, but it could end up with you stuck in a loop with a massive output file getting bigger and bigger due to the system adding the file to itself. To avoid it, two possible solutions.

    A) Put the result in a separate directory to be safe (Thanks @mosh):

    mkdir concatSql
    cat *.sql  > ./concatSql/all_files.sql
    

    B) Concat them in a file with a different extension and then change it the name. (Thanks @William Turrell)

    cat *.sql  > all_files.sql1
    mv all_files.sql1 all_files.sql
    

提交回复
热议问题