【问题标题】:Back up MySQL databases with each table in separate files with a batch file [duplicate]使用批处理文件将每个表备份到单独的文件中的 MySQL 数据库 [重复]
【发布时间】:2018-03-22 11:33:59
【问题描述】:

我正在使用批处理文件在 Windows 上备份我的 MySQL 数据库。如何将每个表保存在单独的文件中?当前批处理文件将所有表保存到每个数据库的一个文件中。

这是批处理文件

FOR /D %%F IN (*) DO (

SET %%F=!%%F:@002d=-!
%mysqldumpexe% --user=%dbuser% --password=%dbpass% --databases --routines --log-error=%errorLogPath% %%F > "%backupfldr%%%F.%backuptime%.sql"

::How- Grab the list of tables inside the current database
::How- Backup current table from the current database into a.sql (database-table_name.sql)
)

【问题讨论】:

  • This question 展示了如何从数据库中检索表列表。
  • 我对批处理不熟悉,所以我不知道如何在循环中实现它
  • 谢谢。相关链接解决了我的问题。

标签: mysql batch-file


【解决方案1】:

您需要使用mysqldump --tab 将每个表保存在单独的文件中。实际上,两个文件:一个用于 DDL 的 .sql 文件和一个用于数据的 .csv 文件。

然后您可以使用mysqlimport --use-threads <n> 以多线程方式从 csv 文件中加载数据。

有关详细信息,请参阅 https://dev.mysql.com/doc/refman/5.7/en/mysqldump.htmlhttps://dev.mysql.com/doc/refman/5.7/en/mysqlimport.html

【讨论】:

    猜你喜欢
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多