从shell导入多个.sql转储文件到mysql数据库

编程入门 行业动态 更新时间:2024-10-10 19:27:19
本文介绍了从shell导入多个.sql转储文件到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个目录,其中包含一堆.sql文件,mysql将这些文件转储到服务器上的每个数据库中.

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

例如

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

实际上有很多.

我需要创建一个shell脚本或单行,可能会导入每个数据库.

I need to create a shell script or single line probably that will import each database.

我正在Linux Debian机器上运行.

I'm running on a Linux Debian machine.

我认为有一种方法可以将ls的结果传递给一些find命令或其他内容.

I thinking there is some way to pipe in the results of a ls into some find command or something..

非常感谢您的帮助和教育.

any help and education is much appreciated.

编辑

所以最终我想一次自动将一个文件导入数据库.

So ultimately I want to automatically import one file at a time into the database.

例如如果我手动做一个,那就是:

E.g. if I did it manually on one it would be:

mysql -u root -ppassword < database1-2011-01-15.sql

推荐答案

cat *.sql | mysql?您是否需要按任何特定顺序使用它们?

cat *.sql | mysql? Do you need them in any specific order?

如果您有太多方法无法处理,请尝试执行以下操作:

If you have too many to handle this way, then try something like:

find . -name '*.sql' | awk '{ print "source",$0 }' | mysql --batch

这也解决了通过管道传递脚本输入时遇到的一些问题,尽管您在Linux下的管道处理上应该没有任何问题.这种方法的好处是,mysql实用程序会读取每个文件,而不是从stdin中读取文件.

This also gets around some problems with passing script input through a pipeline though you shouldn't have any problems with pipeline processing under Linux. The nice thing about this approach is that the mysql utility reads in each file instead of having it read from stdin.

更多推荐

从shell导入多个.sql转储文件到mysql数据库

本文发布于:2023-10-29 00:26:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   数据库   shell   sql   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!