简体   繁体   中英

Mysql dump of single table

I am trying to make some normal (understand restorable) backup of mysql backup. My problem is, that I only need to back up a single table, which was last created, or edited. Is it possible to set mysqldump to do that? Mysql can find the last inserted table, but how can I include it in mysql dump command? I need to do that without locking the table, and the DB has partitioning enabled.... Thanks for help...

For dumping a single table use the below command. Open cmd prompt and type the path of mysql like c:\\program files\\mysql\\bin .
Now type the command:

mysqldump -u username -p password databasename table name > C:\backup\filename.sql

Here
username - your mysql username
password - your mysql password
databasename - your database name
table name - your table name
C:\\backup\\filename.sql - path where the file should save and the filename.

If you want to add the backup table to any other database you can do it by following steps:

  • login to mysql
  • type the below command

    mysql -u username -p password database name < C:\\backup\\filename.sql

You can use this SQL to get the last inserted / updated table :-

select table_schema, table_name 
from information_schema.tables 
where table_schema not in ("mysql", "information_schema", "performance_schema") 
order by greatest(create_time, update_time) desc limit 1;

Once you have the results from this query, you can cooperate it into any other language (for example bash) to produce the exact table dump).

./mysqldump -uroot -proot mysql user > mysql_user.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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