From 739109fe21aa0cb9e2d755db529d6a0c3a0171a2 Mon Sep 17 00:00:00 2001 From: emorino Date: Fri, 27 Oct 2017 14:26:42 +0200 Subject: [PATCH] Ajout extraire une table depuis un dump --- HowtoMySQL.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/HowtoMySQL.md b/HowtoMySQL.md index 3c60d477..49253274 100644 --- a/HowtoMySQL.md +++ b/HowtoMySQL.md @@ -786,6 +786,48 @@ mygrants() } ~~~ +Pour extraire une table depuis un dump (dans le cas où il y a pas de backup avec table séparé) + +Il faut déterminer la structure des tables du dump avec : + +~~~ +grep -n "Table structure" dump.sql +~~~ + +Ce qui donne quelque chose comme ça : + +~~~ +19:-- Table structure for table `wp-cgp` +43:-- Table structure for table `wp_WP_SEO_404_links` +73:-- Table structure for table `wp_WP_SEO_Redirection` +109:-- Table structure for table `wp_WP_SEO_Redirection_LOG` +143:-- Table structure for table `wp_acccess` +170:-- Table structure for table `wp_avant_premiere` +196:-- Table structure for table `wp_commentmeta` +223:-- Table structure for table `wp_comments` +265:-- Table structure for table `wp_icl_string_translations` +294:-- Table structure for table `wp_icl_strings` +322:-- Table structure for table `wp_investments` +396:-- Table structure for table `wp_links` +431:-- Table structure for table `wp_login_redirects` +458:-- Table structure for table `wp_mtouchquiz_answer` +486:-- Table structure for table `wp_mtouchquiz_question` +~~~ + +Si l'on veux extraire la table *wp_investments*, on détermine ou commence et fini la table, ici elle commence a 322 et fini à 395, la fin ce détermine toujours à n-1 de la prochaine table. + +On fait un *sed -n* avec le début et la fin de la table pour l'extraire dans un fichier .sql : + +~~~ +sed -n '[numéro_du_début_de_la_ligne],[numéro_de_fin_de_la_ligne] p' dump.sql > table.sql +~~~ + +Exemple avec la table *wp_investments* : + +~~~ +sed -n '322,395 p' dump.sql > wp_investments.sql +~~~ + ### Restaurer Pour avoir un dump avec un seul insert par ligne, pratique pour restaurer partiellement les bases `mysql.user` et `mysql.db` par exemple :