本文介绍了自动将所有 mysql 表转储到单独的文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将每个 mysql 表的转储转储到单独的文件中.手册指出此语法为

I'd like to get dumps of each mysql table into separate files. The manual indicates that the syntax for this is

mysqldump [options] db_name [tbl_name ...]

这表明您事先知道表名.我现在可以设置知道每个表名称的脚本,但是假设我在路上添加了一个新表而忘记更新转储脚本.然后我缺少一张或多张桌子的转储.

Which indicates that you know the table names before hand. I could set up the script that knows each table name now, but say I add a new table down the road and forget to update the dump script. Then I'm missing dumps for one or more table.

有没有办法将每个现有表自动转储到单独的文件中?或者我将不得不做一些脚本工作;查询数据库,获取所有表名,并按名称转储.

Is there a way to automagically dump each existing table into a separate file? Or am I going to have to do some script-fu; query the database, get all the table names, and dump them by name.

如果我走script-fu路线,什么脚本语言可以访问mysql数据库?

If I go the script-fu route, what scripting langauges can access a mysql database?

推荐答案

mysqldump 命令行程序为您执行此操作 - 尽管 文档对此非常不清楚.

The mysqldump command line program does this for you - although the docs are very unclear about this.

需要注意的一点是 ~/output/dir 必须可由拥有 mysqld 的用户写入.在 Mac OS X 上:

One thing to note is that ~/output/dir has to be writable by the user that owns mysqld. On Mac OS X:

sudo chown -R _mysqld:_mysqld ~/output/dir
mysqldump --user=dbuser --password --tab=~/output/dir dbname

运行上述后,您将拥有一个包含每个表架构(创建表语句)的 tablename.sql 文件和包含数据的 tablename.txt 文件.

After running the above, you will have one tablename.sql file containing each table's schema (create table statement) and tablename.txt file containing the data.

如果您只想使用模式进行转储,请添加 --no-data 标志:

If you want a dump with schema only, add the --no-data flag:

mysqldump --user=dbuser --password --no-data --tab=~/output/dir dbname

这篇关于自动将所有 mysql 表转储到单独的文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 21:49