Last active
March 3, 2021 21:21
-
-
Save xianx/6828501 to your computer and use it in GitHub Desktop.
Revisions
-
xianx revised this gist
Mar 27, 2020 . 1 changed file with 19 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,22 @@ Limiting the number of records from mysqldump mysqldump --opt --where="1 limit 1000000" database that would give you the first million rows from every table. --- As the default order is ASC which is rarely what you want in this situation, you need to have a proper database design to make DESC work out of the box. If all your tables have ONE primary key column with the same name (natural or surrogate) you can easily dump the n latest records using: mysqldump --opt --where="1 ORDER BY id DESC limit 1000000" --all-databases > dump.sql This is a perfect reason to why you should always name your PK's id and avoid composite PK's, even in association tables (use surrogate keys instead). --- f you want to get n records from a specific table you can do something like this: mysqldump --opt --where="1 limit 1000000" database table > dump.sql This will dump the first 1000000 rows from the table named table into the file dump.sql. --- Source : https://techtun.es/hzhzLZ -
xianx renamed this gist
Mar 27, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
xianx revised this gist
Mar 27, 2020 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ Limiting the number of records from mysqldump mysqldump --opt --where="1 limit 1000000" database that would give you the first million rows from every table. -
xianx revised this gist
Nov 1, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,5 +30,5 @@ mysql -u username -p -v Database_Name < /path/to/mysql_DUMP_File_Name.sql **Restoring into another Remote Host database** ``` mysql --host=Host_Name --user=User_Name --password=Password --verbose Database_Name < /path/to/mysql_DUMP_File.sql ``` -
xianx revised this gist
Nov 1, 2018 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,10 @@ mysqldump --user=User_Name --password=Password Database_Name Table_Name > /path/ ``` mysql -u username -p -v Database_Name < /path/to/mysql_DUMP_File_Name.sql ``` **Restoring into another Remote Host database** ``` mysql --host=Host_Name --user=User_Name --password=Password --verbose Database_Name > /path/to/mysql_DUMP_File.sql ``` -
xianx revised this gist
Nov 1, 2018 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,8 +23,8 @@ mysqldump --user=User_Name --password=Password Database_Name Table_Name > /path/ **Restoring the single table into another database** ``` mysql -u username -p -v Database_Name < /path/to/mysql_DUMP_File_Name.sql ``` ``` mysql --user=User_Name --password=Password --verbose Database_Name > /path/to/mysql_DUMP_File.sql ``` File renamed without changes. -
xianx revised this gist
Sep 20, 2017 . No changes.There are no files selected for viewing
-
xianx revised this gist
Sep 20, 2017 . No changes.There are no files selected for viewing
-
xianx revised this gist
Apr 21, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,5 @@ mysqldump -u USERNAME -pPASSWORD -v DATABASENAME > DATABASENAME.sql ** Restore single database with verbose output** ``` mysql -u USERNAME -pPASSWORD -v DATABASENAME < DATABASENAME.sql ``` -
xianx revised this gist
Apr 21, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ ** Backup a single database with verbose output** ``` mysqldump -u USERNAME -pPASSWORD -v DATABASENAME > DATABASENAME.sql ``` ** Restore single database with verbose output** ``` mysql -u USERNAME -pPASSWORD -v DATABASENAME < DATABASENAME.sql -
xianx revised this gist
Apr 21, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ ** Backup a single database with verbose output ``` mysqldump -u USERNAME -pPASSWORD -v DATABASENAME > DATABASENAME.sql ``` ** Restore single database with verbose output ``` mysql -u USERNAME -pPASSWORD -v DATABASENAME < DATABASENAME.sql -
xianx revised this gist
Apr 21, 2015 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,10 @@ *** Backup a single database with verbose output ``` mysqldump -u USERNAME -pPASSWORD -v DATABASENAME > DATABASENAME.sql ``` *** Restore single database with verbose output ``` mysql -u USERNAME -pPASSWORD -v DATABASENAME < DATABASENAME.sql -
xianx revised this gist
Apr 21, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ ### Backup a single database ``` mysqldump -u USERNAME -pPASSWORD -v DATABASENAME > DATABASENAME.sql ``` -
xianx revised this gist
Apr 21, 2015 . 2 changed files with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ ### Backup a single database ``` mqsqldump -u USERNAME -pPASSWORD -v DATABASENAME > DATABASENAME.sql ``` File renamed without changes. -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ ``` mysqldump -u username -p database --ignore-table=database.table1 --ignore-table=database.table2 > database.sql ``` ``` mysqldump -u dave -ppassword -h localhost --ignore-table=my_db_name.my_table_name my_db_name ``` -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ mysqldump --user=User_Name --password=Password --all-databases > /path/to/mysql_ ### Single Table Backup and Restore **Backingup a single table from a database** ``` mysqldump -u username -p Database_Name Table_Name > /path/to/mysql_DUMP_File.sql -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ mysqldump --user=User_Name --password=Password --all-databases > /path/to/mysql_ ### Single Table Backup and Restore **Backup a single table from a database** ``` mysqldump -u username -p Database_Name Table_Name > /path/to/mysql_DUMP_File.sql -
xianx revised this gist
Oct 4, 2013 . 2 changed files with 16 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,36 +1,30 @@ ### 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 ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ mysqldump -u username -p --where="(%OPTION%)" Database_Name Table_Name > /path/to/mysql_DUMP_File.sql ``` __where %OPTION%__ ``` --where="TRUE ORDER BY id DESC LIMIT 1000" -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ ### Latest 'X' Records from a Single Table ``` @@ -16,7 +16,7 @@ mysqldump -u username -p --where="(%OPTION%)" Database_Name Table_Name > /path/ ``` ### Latest 'X' Records from a All Database ``` mysqldump -u User_Name -p --where="true limit 1000" --all-databases > /path/to/mysql_DUMP_File.sql -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ ## Latest 'X' Records from a Single Table ``` mysqldump -u username -p --where="(%OPTION%)" Database_Name Table_Name > /path/to/mysql_DUMP_File.sql @@ -16,8 +16,7 @@ mysqldump -u username -p --where="(%OPTION%)" Database_Name Table_Name > /path/ ``` ## Latest 'X' Records from a All Database ``` mysqldump -u User_Name -p --where="true limit 1000" --all-databases > /path/to/mysql_DUMP_File.sql -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,22 +9,21 @@ mysqldump -u username -p --where="(%OPTION%)" Database_Name Table_Name > /path/ **where %OPTION%** ``` --where="TRUE ORDER BY id DESC LIMIT 1000" --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 All Database ---- ``` 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 -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ 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" -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ 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" -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ 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" -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ 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" -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ 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" -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,10 +3,10 @@ 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" -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Latest 'X' Records from a Single Table ---- ``` mysqldump -u username -p --where="(OPTION)" Database_Name Table_Name > /path/to/mysql_DUMP_File.sql ``` #### --where -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 6 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,29 +6,17 @@ Latest 'X' Records from a Single Table mysqldump -u username -p --where="true LIMIT 1000" Database_Name Table_Name > /path/to/mysql_DUMP_File.sql ``` #### --where ``` --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 ---- ``` -
xianx revised this gist
Oct 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ Latest 'X' Records from a Single Table mysqldump -u username -p --where="true LIMIT 1000" Database_Name Table_Name > /path/to/mysql_DUMP_File.sql ``` ### --where ``` mysqldump --where="TRUE LIMIT 500"
NewerOlder