bash – mysqldump与db在一个单独的文件

我正在编写一个单行命令,将所有数据库备份到各自的名称中,而不是使用一个sql中的转储。

例如:db1保存到db1.sql,db2保存到db2.sql

到目前为止,我收集了以下命令来检索所有数据库

MysqL -uuname -ppwd -e 'show databases' | grep -v 'Database'

我打算用awk来管理它

awk '{MysqLdump -uuname -ppwd $1 > $1.sql}'

但这不工作。

我是bash的新手,所以我的想法可能是错的。
我应该怎么做才能使其在各自的名称中导出db?

更新:
好的,必须终于设法从下面的提示中得到它的工作。
这是最后的脚本

# replace [] with your own config
# replace own dir to save
# echo doesn't work. hmm...

MysqL -u[uname] -p'[pwd]' -e "show databases" \
| grep -Ev 'Database|information_schema' \
| while read dbname; \
do \
echo 'Dumping $dbname' \
MysqLdump -u[uanme] -p'[pwd]' $dbname > ~/db_backup/$dbname.sql;\
done

回音部分不行。

MysqL -uroot -e 'show databases' | while read dbname; do MysqLdump -uroot --complete-insert --some-other-options "$dbname" > "$dbname".sql; done

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...