Import Multiple .sql dump files into mysql database from shell

前端 未结 5 1821
半阙折子戏
半阙折子戏 2020-12-12 14:06

I have a directory with a bunch of .sql files that mysql dumps of each database on my server.

e.g.

database1-2011-01-15.sql
database2-2         


        
5条回答
  •  青春惊慌失措
    2020-12-12 14:33

    I created a script some time ago to do precisely this, which I called (completely uncreatively) "myload". It loads SQL files into MySQL.

    Here it is on GitHub

    It's simple and straight-forward; allows you to specify mysql connection parameters, and will decompress gzip'ed sql files on-the-fly. It assumes you have a file per database, and the base of the filename is the desired database name.

    So:

    myload foo.sql bar.sql.gz
    

    Will create (if not exist) databases called "foo" and "bar", and import the sql file into each.

    For the other side of the process, I wrote this script (mydumpall) which creates the corresponding sql (or sql.gz) files for each database (or some subset specified either by name or regex).

提交回复
热议问题