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

后端 未结 11 1785
一整个雨季
一整个雨季 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:27

    The easiest solution is to copy/paste every sql files in one.

    You can't add some sql markup for file importation (the imported files will be in your computer, not in the server, and I don't think MySQL manage some import markup for external sql files).

    0 讨论(0)
  • 2021-01-29 20:37

    just type:

    cat *.sql |mysql -uroot -p
    

    and mysql will import all the sql file in sequence

    0 讨论(0)
  • 2021-01-29 20:38

    This is the easiest way that I have found.

    In Windows (powershell):

    cat *.sql | C:\wamp64\bin\mysql\mysql5.7.21\bin\mysql.exe -u user -p database

    You will need to insert the path to your WAMP - MySQL above, I have used my systems path.

    In Linux (Bash):

    cat *.sql | mysql -u user -p database

    0 讨论(0)
  • 2021-01-29 20:38

    I know it's been a little over two years... but I was looking for a way to do this, and wasn't overly happy with the solution posted (it works fine, but I wanted a little more information as the import happens). When combining all the SQL files in to one, you don't get any sort of progress updates.

    So I kept digging for an answer and thought this might be a good place to post what I found for future people looking for the same answer. Here's a command line in Windows that will import multiple SQL files from a folder. You run this from the command line while in the directory where mysql.exe is located.

    for /f %f in ('dir /b <dir>\<mask>') do mysql --user=<user> --password=<password> <dbname> < <dir>\%f
    

    With some assumed values (as an example):

    for /f %f in ('dir /b c:\sqlbackup\*.sql') do mysql --user=mylogin --password=mypass mydb < c:\sqlbackup\%f
    

    If you had two sets of SQL backups in the folder, you could change the *.sql to something more specific (like mydb_*.sql).

    0 讨论(0)
  • 2021-01-29 20:38

    in windows open windows powershell and go to the folder where sql files are then run this command

    cat *.sql |  C:\xampp\mysql\bin\mysql.exe -u username -p databasename
    
    0 讨论(0)
提交回复
热议问题