Home  >  Article  >  Database  >  巧用Linux管道,让MySQL执行大量脚本文件

巧用Linux管道,让MySQL执行大量脚本文件

WBOY
WBOYOriginal
2016-06-07 16:52:571592browse

在工作中碰到这样的需求,要mysql执行大量脚本来更新数据库。查了mysql的source命令,只能执行一个脚本文件。我试了source /sqkd

  在工作中碰到这样的需求,要mysql执行大量脚本来更新数据库。查了mysql的source命令,只能执行一个脚本文件。我试了source /sqkdir/*.sql;不行。mysql不能把*.sql作为文件名通配符来处理。后来请教了别人,,找到了办法。利用Linux管道,执行如下命令:

  cat /sqldir/*.sql | mysql -u username -p

  这样就实现了让mysql执行大量脚本文件。

  原理是这样的,cat会把所有的文件链接起来输出到缺省输出,然后用管道把这些文件输出到mysql,mysql将这些文件作为输入,会执行其中的脚本。

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn