简体   繁体   English

通过SSH将数据库表分别导出到sql文件

[英]Export database tables to sql files individually through SSH

As the question says, I have been trying to export each table of a database in individual .sql files. 正如问题所述,我一直在尝试将数据库的每个表导出为单独的.sql文件。 I know mysqldump -u username -p DBName TableName > Export.sql exports one specific table, but is there any way I can loop it and export all tables in individual files using SSH command? 我知道mysqldump -u username -p DBName TableName > Export.sqlmysqldump -u username -p DBName TableName > Export.sql导出一个特定的表,但是有什么办法可以使它循环并使用SSH命令将所有表导出到单个文件中?

Find the tables in the database and iterate over it. 在数据库中找到表并对其进行迭代。

mysql -u USERNAME -p -N -D DATABASENAME -e 'show tables';

This will list the tables of a particular database. 这将列出特定数据库的表。 Do something like this to export all the tables of the database. 做这样的事情来导出数据库的所有表。 ( Note: you need to remove the formatting charaters ) 注意:您需要删除格式字符

for tab in `mysql -u USERNAME -p -N -D DATABASENAME -e 'show tables';` do
    mysqldump -u USERNAME -p DATABASENAME $tab > ${tab}.sql
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM