Senin, 18 Maret 2019

Restoring MULTIPLE MySQL databases from one file at the command line?





















13






























I have exported all my databases to a file using phpMyAdmin.



Unfortunately I don't have a working phpMyAdmin in my destination system.



How should I restore all of them at once using one line command?

















share|improve this question







































  • 1











    Did you take a look into the file? It should/could contain commands to create and switch to the databases as needed.



    – Tom Regner

    Oct 9 '12 at 12:42























  • Yes, databases are created and then they have been selected using USE database_name command.



    – smhnaji

    Oct 9 '12 at 12:45























  • Then Unni and laurents answers are correct.



    – Tom Regner

    Oct 9 '12 at 13:14






























13






























I have exported all my databases to a file using phpMyAdmin.



Unfortunately I don't have a working phpMyAdmin in my destination system.



How should I restore all of them at once using one line command?

















share|improve this question







































  • 1











    Did you take a look into the file? It should/could contain commands to create and switch to the databases as needed.



    – Tom Regner

    Oct 9 '12 at 12:42























  • Yes, databases are created and then they have been selected using USE database_name command.



    – smhnaji

    Oct 9 '12 at 12:45























  • Then Unni and laurents answers are correct.



    – Tom Regner

    Oct 9 '12 at 13:14


























13






















13














13


4










I have exported all my databases to a file using phpMyAdmin.



Unfortunately I don't have a working phpMyAdmin in my destination system.



How should I restore all of them at once using one line command?

















share|improve this question






























I have exported all my databases to a file using phpMyAdmin.



Unfortunately I don't have a working phpMyAdmin in my destination system.



How should I restore all of them at once using one line command?








mysql phpmyadmin










share|improve this question



























share|improve this question























share|improve this question





share|improve this question










edited Jan 30 '14 at 0:48













Flyk



1,38931624







1,38931624















asked Oct 9 '12 at 12:29













smhnajismhnaji



2021211







2021211














  • 1











    Did you take a look into the file? It should/could contain commands to create and switch to the databases as needed.



    – Tom Regner

    Oct 9 '12 at 12:42























  • Yes, databases are created and then they have been selected using USE database_name command.



    – smhnaji

    Oct 9 '12 at 12:45























  • Then Unni and laurents answers are correct.



    – Tom Regner

    Oct 9 '12 at 13:14

























  • 1











    Did you take a look into the file? It should/could contain commands to create and switch to the databases as needed.



    – Tom Regner

    Oct 9 '12 at 12:42























  • Yes, databases are created and then they have been selected using USE database_name command.



    – smhnaji

    Oct 9 '12 at 12:45























  • Then Unni and laurents answers are correct.



    – Tom Regner

    Oct 9 '12 at 13:14














1







1









Did you take a look into the file? It should/could contain commands to create and switch to the databases as needed.



– Tom Regner

Oct 9 '12 at 12:42









Did you take a look into the file? It should/could contain commands to create and switch to the databases as needed.



– Tom Regner

Oct 9 '12 at 12:42





















Yes, databases are created and then they have been selected using USE database_name command.



– smhnaji

Oct 9 '12 at 12:45









Yes, databases are created and then they have been selected using USE database_name command.



– smhnaji

Oct 9 '12 at 12:45





















Then Unni and laurents answers are correct.



– Tom Regner

Oct 9 '12 at 13:14









Then Unni and laurents answers are correct.



– Tom Regner

Oct 9 '12 at 13:14

















4 Answers

4











active



oldest



votes





































18




























Why don't you concat all the files into one single file and import/restore using



mysql -u username -p < dump.sql



Create one file using



mysqldump -u username -p --all-databases > dump.sql









share|improve this answer



















































  • The OP already has a single file and he needs to restore the files so he can't dump them anymore I suppose.



    – laurent

    Oct 9 '12 at 12:59























  • @laurent Yes got it. Using mysql -u username -p < dump.sql will load the multiple mysql database.



    – devav2

    Oct 9 '12 at 13:05



























  • yes, sure it will



    – laurent

    Oct 9 '12 at 13:07













  • 2











    it did not work for me. it says i need to select a databse



    – Aryeh Armon

    Jul 7 '15 at 9:22






































3




























If you backed up many database to 1 file, I suppose you backed up the create database statements in the same file. If not you only need to add the create database and use database statements to your file at the proper places.



After that, the command to load the file to mysql is:



mysql -p < sqlfile.sql



-p is to ask for your password.



You can use -u username if you need to use another user.









share|improve this answer

































































    1




























    mysql command to restore sql file is :



    mysql DATABASE_NAME < SQL_FILENAME.sql



    first make sure that file is sql. Incase it ends with gz file extension, you need to uncompress using command :



    gunzip SQL_FILE.sql.gz









    share|improve this answer















































    • -1 . As I said in the above, there are MULTIPLE databases stored in the file and I want all of them to be restored at once.



      – smhnaji

      Oct 9 '12 at 12:38



























    • can you export each database separately in phpmyadmin and restore it at source server ? or use linux stream editors such as sed or awk to split them in different file.



      – Unni

      Oct 9 '12 at 12:47













    • 1











      no need, he can import all the databases from a single file



      – laurent

      Oct 9 '12 at 13:01






































    -1




























    You may restore databases with the help of sql 2005 repair database



    http://www.sqlserverrepairtoolbox.com repairs data types, views, procedures, tables, keys, indexes and other objects









    share|improve this answer















































    • This does not answer the original question. SQL Server Repair Toolbox is a proprietary Windows program that does not work from the Ubuntu command line.



      – karel

      4 hours ago


























    Your Answer















    StackExchange.ready(function() {

    var channelOptions = {

    tags: "".split(" "),

    id: "89"

    };

    initTagRenderer("".split(" "), "".split(" "), channelOptions);



    StackExchange.using("externalEditor", function() {

    // Have to fire editor after snippets, if snippets enabled

    if (StackExchange.settings.snippets.snippetsEnabled) {

    StackExchange.using("snippets", function() {

    createEditor();

    });

    }

    else {

    createEditor();

    }

    });



    function createEditor() {

    StackExchange.prepareEditor({

    heartbeatType: 'answer',

    autoActivateHeartbeat: false,

    convertImagesToLinks: true,

    noModals: true,

    showLowRepImageUploadWarning: true,

    reputationToPostImages: 10,

    bindNavPrevention: true,

    postfix: "",

    imageUploader: {

    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",

    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",

    allowUrls: true

    },

    onDemand: true,

    discardSelector: ".discard-answer"

    ,immediatelyShowMarkdownHelp:true

    });





    }

    });




























    draft saved


    draft discarded



































    StackExchange.ready(

    function () {

    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f198170%2frestoring-multiple-mysql-databases-from-one-file-at-the-command-line%23new-answer', 'question_page');

    }

    );



    Post as a guest




























    Required, but never shown














































    4 Answers

    4











    active



    oldest



    votes















    4 Answers

    4











    active



    oldest



    votes

















    active



    oldest



    votes











    active



    oldest



    votes

















    18




























    Why don't you concat all the files into one single file and import/restore using



    mysql -u username -p < dump.sql



    Create one file using



    mysqldump -u username -p --all-databases > dump.sql









    share|improve this answer



















































    • The OP already has a single file and he needs to restore the files so he can't dump them anymore I suppose.



      – laurent

      Oct 9 '12 at 12:59























    • @laurent Yes got it. Using mysql -u username -p < dump.sql will load the multiple mysql database.



      – devav2

      Oct 9 '12 at 13:05



























    • yes, sure it will



      – laurent

      Oct 9 '12 at 13:07













    • 2











      it did not work for me. it says i need to select a databse



      – Aryeh Armon

      Jul 7 '15 at 9:22






























    18




























    Why don't you concat all the files into one single file and import/restore using



    mysql -u username -p < dump.sql



    Create one file using



    mysqldump -u username -p --all-databases > dump.sql









    share|improve this answer



















































    • The OP already has a single file and he needs to restore the files so he can't dump them anymore I suppose.



      – laurent

      Oct 9 '12 at 12:59























    • @laurent Yes got it. Using mysql -u username -p < dump.sql will load the multiple mysql database.



      – devav2

      Oct 9 '12 at 13:05



























    • yes, sure it will



      – laurent

      Oct 9 '12 at 13:07













    • 2











      it did not work for me. it says i need to select a databse



      – Aryeh Armon

      Jul 7 '15 at 9:22


























    18






















    18














    18










    Why don't you concat all the files into one single file and import/restore using



    mysql -u username -p < dump.sql



    Create one file using



    mysqldump -u username -p --all-databases > dump.sql









    share|improve this answer




























    Why don't you concat all the files into one single file and import/restore using



    mysql -u username -p < dump.sql



    Create one file using



    mysqldump -u username -p --all-databases > dump.sql









    share|improve this answer

























    share|improve this answer



    share|improve this answer










    edited 9 hours ago













    Pablo Bianchi



    2,4451530







    2,4451530















    answered Oct 9 '12 at 12:51













    devav2devav2



    24.7k126979







    24.7k126979
























    • The OP already has a single file and he needs to restore the files so he can't dump them anymore I suppose.



      – laurent

      Oct 9 '12 at 12:59























    • @laurent Yes got it. Using mysql -u username -p < dump.sql will load the multiple mysql database.



      – devav2

      Oct 9 '12 at 13:05



























    • yes, sure it will



      – laurent

      Oct 9 '12 at 13:07













    • 2











      it did not work for me. it says i need to select a databse



      – Aryeh Armon

      Jul 7 '15 at 9:22



































    • The OP already has a single file and he needs to restore the files so he can't dump them anymore I suppose.



      – laurent

      Oct 9 '12 at 12:59























    • @laurent Yes got it. Using mysql -u username -p < dump.sql will load the multiple mysql database.



      – devav2

      Oct 9 '12 at 13:05



























    • yes, sure it will



      – laurent

      Oct 9 '12 at 13:07













    • 2











      it did not work for me. it says i need to select a databse



      – Aryeh Armon

      Jul 7 '15 at 9:22




























    The OP already has a single file and he needs to restore the files so he can't dump them anymore I suppose.



    – laurent

    Oct 9 '12 at 12:59









    The OP already has a single file and he needs to restore the files so he can't dump them anymore I suppose.



    – laurent

    Oct 9 '12 at 12:59





















    @laurent Yes got it. Using mysql -u username -p < dump.sql will load the multiple mysql database.



    – devav2

    Oct 9 '12 at 13:05













    @laurent Yes got it. Using mysql -u username -p < dump.sql will load the multiple mysql database.



    – devav2

    Oct 9 '12 at 13:05

























    yes, sure it will



    – laurent

    Oct 9 '12 at 13:07









    yes, sure it will



    – laurent

    Oct 9 '12 at 13:07







    2







    2









    it did not work for me. it says i need to select a databse



    – Aryeh Armon

    Jul 7 '15 at 9:22









    it did not work for me. it says i need to select a databse



    – Aryeh Armon

    Jul 7 '15 at 9:22





















    3




























    If you backed up many database to 1 file, I suppose you backed up the create database statements in the same file. If not you only need to add the create database and use database statements to your file at the proper places.



    After that, the command to load the file to mysql is:



    mysql -p < sqlfile.sql



    -p is to ask for your password.



    You can use -u username if you need to use another user.









    share|improve this answer

























































      3




























      If you backed up many database to 1 file, I suppose you backed up the create database statements in the same file. If not you only need to add the create database and use database statements to your file at the proper places.



      After that, the command to load the file to mysql is:



      mysql -p < sqlfile.sql



      -p is to ask for your password.



      You can use -u username if you need to use another user.









      share|improve this answer





















































        3






















        3














        3










        If you backed up many database to 1 file, I suppose you backed up the create database statements in the same file. If not you only need to add the create database and use database statements to your file at the proper places.



        After that, the command to load the file to mysql is:



        mysql -p < sqlfile.sql



        -p is to ask for your password.



        You can use -u username if you need to use another user.









        share|improve this answer




























        If you backed up many database to 1 file, I suppose you backed up the create database statements in the same file. If not you only need to add the create database and use database statements to your file at the proper places.



        After that, the command to load the file to mysql is:



        mysql -p < sqlfile.sql



        -p is to ask for your password.



        You can use -u username if you need to use another user.









        share|improve this answer

























        share|improve this answer



        share|improve this answer










        edited Oct 9 '12 at 13:02







































        answered Oct 9 '12 at 12:48













        laurentlaurent



        5,2091923







        5,2091923





































            1




























            mysql command to restore sql file is :



            mysql DATABASE_NAME < SQL_FILENAME.sql



            first make sure that file is sql. Incase it ends with gz file extension, you need to uncompress using command :



            gunzip SQL_FILE.sql.gz









            share|improve this answer















































            • -1 . As I said in the above, there are MULTIPLE databases stored in the file and I want all of them to be restored at once.



              – smhnaji

              Oct 9 '12 at 12:38



























            • can you export each database separately in phpmyadmin and restore it at source server ? or use linux stream editors such as sed or awk to split them in different file.



              – Unni

              Oct 9 '12 at 12:47













            • 1











              no need, he can import all the databases from a single file



              – laurent

              Oct 9 '12 at 13:01






























            1




























            mysql command to restore sql file is :



            mysql DATABASE_NAME < SQL_FILENAME.sql



            first make sure that file is sql. Incase it ends with gz file extension, you need to uncompress using command :



            gunzip SQL_FILE.sql.gz









            share|improve this answer















































            • -1 . As I said in the above, there are MULTIPLE databases stored in the file and I want all of them to be restored at once.



              – smhnaji

              Oct 9 '12 at 12:38



























            • can you export each database separately in phpmyadmin and restore it at source server ? or use linux stream editors such as sed or awk to split them in different file.



              – Unni

              Oct 9 '12 at 12:47













            • 1











              no need, he can import all the databases from a single file



              – laurent

              Oct 9 '12 at 13:01


























            1






















            1














            1










            mysql command to restore sql file is :



            mysql DATABASE_NAME < SQL_FILENAME.sql



            first make sure that file is sql. Incase it ends with gz file extension, you need to uncompress using command :



            gunzip SQL_FILE.sql.gz









            share|improve this answer
























            mysql command to restore sql file is :



            mysql DATABASE_NAME < SQL_FILENAME.sql



            first make sure that file is sql. Incase it ends with gz file extension, you need to uncompress using command :



            gunzip SQL_FILE.sql.gz









            share|improve this answer





















            share|improve this answer



            share|improve this answer














            answered Oct 9 '12 at 12:36













            UnniUnni



            24622







            24622
























            • -1 . As I said in the above, there are MULTIPLE databases stored in the file and I want all of them to be restored at once.



              – smhnaji

              Oct 9 '12 at 12:38



























            • can you export each database separately in phpmyadmin and restore it at source server ? or use linux stream editors such as sed or awk to split them in different file.



              – Unni

              Oct 9 '12 at 12:47













            • 1











              no need, he can import all the databases from a single file



              – laurent

              Oct 9 '12 at 13:01



































            • -1 . As I said in the above, there are MULTIPLE databases stored in the file and I want all of them to be restored at once.



              – smhnaji

              Oct 9 '12 at 12:38



























            • can you export each database separately in phpmyadmin and restore it at source server ? or use linux stream editors such as sed or awk to split them in different file.



              – Unni

              Oct 9 '12 at 12:47













            • 1











              no need, he can import all the databases from a single file



              – laurent

              Oct 9 '12 at 13:01




























            -1 . As I said in the above, there are MULTIPLE databases stored in the file and I want all of them to be restored at once.



            – smhnaji

            Oct 9 '12 at 12:38













            -1 . As I said in the above, there are MULTIPLE databases stored in the file and I want all of them to be restored at once.



            – smhnaji

            Oct 9 '12 at 12:38

























            can you export each database separately in phpmyadmin and restore it at source server ? or use linux stream editors such as sed or awk to split them in different file.



            – Unni

            Oct 9 '12 at 12:47









            can you export each database separately in phpmyadmin and restore it at source server ? or use linux stream editors such as sed or awk to split them in different file.



            – Unni

            Oct 9 '12 at 12:47







            1







            1









            no need, he can import all the databases from a single file



            – laurent

            Oct 9 '12 at 13:01









            no need, he can import all the databases from a single file



            – laurent

            Oct 9 '12 at 13:01



















            -1




























            You may restore databases with the help of sql 2005 repair database



            http://www.sqlserverrepairtoolbox.com repairs data types, views, procedures, tables, keys, indexes and other objects









            share|improve this answer















































            • This does not answer the original question. SQL Server Repair Toolbox is a proprietary Windows program that does not work from the Ubuntu command line.



              – karel

              4 hours ago


































            -1




























            You may restore databases with the help of sql 2005 repair database



            http://www.sqlserverrepairtoolbox.com repairs data types, views, procedures, tables, keys, indexes and other objects









            share|improve this answer















































            • This does not answer the original question. SQL Server Repair Toolbox is a proprietary Windows program that does not work from the Ubuntu command line.



              – karel

              4 hours ago






























            -1






















            -1














            -1










            You may restore databases with the help of sql 2005 repair database



            http://www.sqlserverrepairtoolbox.com repairs data types, views, procedures, tables, keys, indexes and other objects









            share|improve this answer
























            You may restore databases with the help of sql 2005 repair database



            http://www.sqlserverrepairtoolbox.com repairs data types, views, procedures, tables, keys, indexes and other objects









            share|improve this answer





















            share|improve this answer



            share|improve this answer














            answered Apr 6 '13 at 14:19













            jerome47_firshteinjerome47_firshtein



            1







            1
























            • This does not answer the original question. SQL Server Repair Toolbox is a proprietary Windows program that does not work from the Ubuntu command line.



              – karel

              4 hours ago







































            • This does not answer the original question. SQL Server Repair Toolbox is a proprietary Windows program that does not work from the Ubuntu command line.



              – karel

              4 hours ago
































            This does not answer the original question. SQL Server Repair Toolbox is a proprietary Windows program that does not work from the Ubuntu command line.



            – karel

            4 hours ago













            This does not answer the original question. SQL Server Repair Toolbox is a proprietary Windows program that does not work from the Ubuntu command line.



            – karel

            4 hours ago




































            draft saved


            draft discarded





















































































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            draft saved


            draft discarded



















            StackExchange.ready(

            function () {

            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f198170%2frestoring-multiple-mysql-databases-from-one-file-at-the-command-line%23new-answer', 'question_page');

            }

            );



            Post as a guest




























            Required, but never shown















































































            Required, but never shown
























            Required, but never shown




















            Required, but never shown











            Required, but never shown



















































            Required, but never shown
























            Required, but never shown




















            Required, but never shown











            Required, but never shown









            Restoring MULTIPLE MySQL databases from one file at the command line? Rating: 4.5 Diposkan Oleh: Admin

            0 komentar:

            Posting Komentar

            Popular Posts