Import Multiple .sql dump files into mysql database from shell

前端 未结 5 1812
半阙折子戏
半阙折子戏 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条回答
  •  -上瘾入骨i
    2020-12-12 14:30

    One-liner to read in all .sql files and imports them:

    for SQL in *.sql; do DB=${SQL/\.sql/}; echo importing $DB; mysql $DB < $SQL; done
    

    The only trick is the bash substring replacement to strip out the .sql to get the database name.

提交回复
热议问题