用分贝mysqldump的一个单独的文件 [英] mysqldump with db in a separate file

查看:154
本文介绍了用分贝mysqldump的一个单独的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写备份所有数据库纳入各自的名称,而不是用倾倒在一个SQL单行命令。

例如:DB1被保存到db1.sql和DB2被保存到db2.sql

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

  mysql的-uuname -ppwd -e'显示数据库| grep的-v数据库

我打算用管道使用awk做类似的东西。

 的awk'{mysqldump的-uuname -ppwd $ 1 GT; $ 1.SQL}

但是,这并不正常工作。

我是新来的bash,所以我可能是错在我的思想。结果
我应该怎么做,使导出数据库在各自的名字呢?

更新:结果
好吧,不得不终于设法得到它从提示工作的下面。结果
这是最后的剧本

 #替换[]与你自己的配置
#替换自己的目录保存
#回声不工作。嗯...MySQL的-u [UNAME] -p[密码]'-e显示数据库\\
| grep的-ev数据库| INFORMATION_SCHEMA'\\
|而读DBNAME; \\
做\\
回声倾销$ DBNAME'\\
mysqldump的-u [uanme] -p[密码]'$ DBNAME> 〜/在db_backup / $ dbname.sql; \\
DONE

的呼应部分不工作,虽然。


解决方案

 的mysql -uroot -e'显示数据库|而读DBNAME;做的mysqldump -uroot --complete插入 - 有些-其他选项$ DBNAME> $ DBNAME.SQL; DONE

I'm writing a single line command that backups all databases into their respective names instead using of dumping all in one sql.

Eg: db1 get saved to db1.sql and db2 gets saved to db2.sql

So far, I'd gathered the following commands to retrieve all databases.

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

I'm planning to pipe it with awk to do something like

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

But that doesn't work.

I'm new to bash, so I could be wrong in my thinking.
What should I do to make it export the db in their respective names?

update:
Ok, have to finally managed to get it working from the hints below.
This is the final script

# 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

The echoing part of doesn't work though.

解决方案

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

这篇关于用分贝mysqldump的一个单独的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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