如何轻松地将多个sql文件导入MySQL数据库? [英] How to easily import multiple sql files into a MySQL database?

查看:324
本文介绍了如何轻松地将多个sql文件导入MySQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个sql文件,我想一次导入所有这些文件到MySQL数据库中.

我转到PHPMyAdmin,访问数据库,单击import,选择一个文件并将其导入.当我有多个文件时,将花费很长时间.

我想知道是否有更好的方法来导入多个文件,例如一个文件将导入其他文件或类似文件.

我正在使用WAMP,我想要一个不需要在计算机上安装其他程序的解决方案.

解决方案

Windows 中,打开一个终端,转到内容文件夹并输入:

copy /b *.sql all_files.sql

这仅将所有文件连接在一起,因此可以非常快速地使用PhpMyAdmin导入.

正如@BlackCharly指出的,在 Linux macOS 中,这将达到目的:

cat *.sql  > .all_files.sql

重要提示:直接执行该操作应该会顺利进行,但由于系统将文件添加到自身中,因此最终可能会陷入一个循环,一个庞大的输出文件会变得越来越大.为了避免这种情况,有两种可能的解决方案.

A)将结果放在一个单独的目录中以确保安全(感谢@mosh):

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

B)将它们连接到具有不同扩展名的文件中,然后将其更改为名称. (感谢@William Turrell)

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

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 database, click import, select a file and import it. When I have more than a couple of files it takes a long time.

I would like to know if there is a better way to import multiple files, something like one file which will import the other files or similar.

I'm using WAMP and I would like a solution that does not require installing additional programs on my computer.

解决方案

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

这篇关于如何轻松地将多个sql文件导入MySQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆