Skip to content

Instantly share code, notes, and snippets.

@xianx
Last active March 3, 2021 21:21
Show Gist options
  • Select an option

  • Save xianx/6828501 to your computer and use it in GitHub Desktop.

Select an option

Save xianx/6828501 to your computer and use it in GitHub Desktop.
MySQL Command

Latest 'X' Records from a Single Table

mysqldump -u username -p --where="(%OPTION%)" Database_Name Table_Name  > /path/to/mysql_DUMP_File.sql

where %OPTION%

--where="TRUE LIMIT 500"
--where="mailbox_id=45"
--where="mailbox_id=45 AND TRUE ORDER BY id DESC LIMIT 300"

Latest 'X' Records from a Single Table

mysqldump -u User_Name -p --where="true limit 1000" --all-databases > /path/to/mysql_DUMP_File.sql

--opt => Shorthand for --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset

**************************************************
*
* All Database Backup and Restore
*
**************************************************
#Backingup all database
mysqldump --user=User_Name --password=Password --all-databases > /path/to/mysql_DUMP_File.sql
**************************************************
*
* Single Table Backup and Restore
*
**************************************************
#Backuping a single table from a database
mysqldump -u username -p Database_Name Table_Name > /path/to/mysql_DUMP_File.sql
mysqldump --user=User_Name --password=Password Database_Name Table_Name > /path/to/mysql_DUMP_File.sql
#Restoring the single table into another database
mysql -u username -p Database_Name < /path/to/mysql_DUMP_File_Name.sql
mysql --user=User_Name --password=Password Database_Name > /path/to/mysql_DUMP_File.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment