How can I import a database using command line?











up vote
1
down vote

favorite
1












I am using Ubuntu 14.04. I want to import my database which is located on the server /var/www/backup.zip. Also I've SSH access using Putty. Noted that MySQL and phpMyadmin are installed on the server.



When I run this command



mysql -u root -p spy < /var/www/backup.zip


nothing happens. A newline shows which starts with ->.



What should I do now?



enter image description here










share|improve this question
























  • You ran the mysql command inside mysql?
    – muru
    Aug 23 '17 at 5:46










  • @muru Not sure what you mean exactly, but yes, as you see, there is mysql> at the beginning of the line.
    – stack
    Aug 23 '17 at 5:47






  • 1




    How to import an SQL file using the command line in MySQL?
    – d a i s y
    Aug 23 '17 at 10:26















up vote
1
down vote

favorite
1












I am using Ubuntu 14.04. I want to import my database which is located on the server /var/www/backup.zip. Also I've SSH access using Putty. Noted that MySQL and phpMyadmin are installed on the server.



When I run this command



mysql -u root -p spy < /var/www/backup.zip


nothing happens. A newline shows which starts with ->.



What should I do now?



enter image description here










share|improve this question
























  • You ran the mysql command inside mysql?
    – muru
    Aug 23 '17 at 5:46










  • @muru Not sure what you mean exactly, but yes, as you see, there is mysql> at the beginning of the line.
    – stack
    Aug 23 '17 at 5:47






  • 1




    How to import an SQL file using the command line in MySQL?
    – d a i s y
    Aug 23 '17 at 10:26













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I am using Ubuntu 14.04. I want to import my database which is located on the server /var/www/backup.zip. Also I've SSH access using Putty. Noted that MySQL and phpMyadmin are installed on the server.



When I run this command



mysql -u root -p spy < /var/www/backup.zip


nothing happens. A newline shows which starts with ->.



What should I do now?



enter image description here










share|improve this question















I am using Ubuntu 14.04. I want to import my database which is located on the server /var/www/backup.zip. Also I've SSH access using Putty. Noted that MySQL and phpMyadmin are installed on the server.



When I run this command



mysql -u root -p spy < /var/www/backup.zip


nothing happens. A newline shows which starts with ->.



What should I do now?



enter image description here







command-line mysql database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 23 '17 at 10:29









d a i s y

3,21982244




3,21982244










asked Aug 23 '17 at 5:40









stack

171118




171118












  • You ran the mysql command inside mysql?
    – muru
    Aug 23 '17 at 5:46










  • @muru Not sure what you mean exactly, but yes, as you see, there is mysql> at the beginning of the line.
    – stack
    Aug 23 '17 at 5:47






  • 1




    How to import an SQL file using the command line in MySQL?
    – d a i s y
    Aug 23 '17 at 10:26


















  • You ran the mysql command inside mysql?
    – muru
    Aug 23 '17 at 5:46










  • @muru Not sure what you mean exactly, but yes, as you see, there is mysql> at the beginning of the line.
    – stack
    Aug 23 '17 at 5:47






  • 1




    How to import an SQL file using the command line in MySQL?
    – d a i s y
    Aug 23 '17 at 10:26
















You ran the mysql command inside mysql?
– muru
Aug 23 '17 at 5:46




You ran the mysql command inside mysql?
– muru
Aug 23 '17 at 5:46












@muru Not sure what you mean exactly, but yes, as you see, there is mysql> at the beginning of the line.
– stack
Aug 23 '17 at 5:47




@muru Not sure what you mean exactly, but yes, as you see, there is mysql> at the beginning of the line.
– stack
Aug 23 '17 at 5:47




1




1




How to import an SQL file using the command line in MySQL?
– d a i s y
Aug 23 '17 at 10:26




How to import an SQL file using the command line in MySQL?
– d a i s y
Aug 23 '17 at 10:26










3 Answers
3






active

oldest

votes

















up vote
5
down vote



accepted










I believe the format is:



mysql -u username -p database_name < /path/to/file.sql


From within mysql:



mysql> use db_name;
mysql> source backup-file.sql;





share|improve this answer























  • well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql) and mine (mysql -u root -p spy < /var/www/backup.zip)?
    – stack
    Aug 23 '17 at 6:04






  • 3




    @stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
    – muru
    Aug 23 '17 at 6:08












  • @muru Ah I see. thank you guys. (btw I think you could say so 30min ago :))
    – stack
    Aug 23 '17 at 6:11




















up vote
0
down vote













A query normally consists of an SQL statement followed by a semicolon.
Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:



mysql> SELECT USER()
->


If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.



Read more here



You just need to add the missing semicolon.






share|improve this answer








New contributor




Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    0
    down vote













    The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.



    The second issue is that you have a zip file and not a SQL file so you need to unzip it first.



    How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:



    unzip -p /var/www/backup.zip | mysql -u root -p mydb


    unzip -p unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.



    mysql -u root -p mydb is going to prompt you for a password (the -p without a value) and then attempt to pipe in the file data to mydb - change the mydb to your own database. You shouldn't specify the password in the command line as it then remains in your command history.






    share|improve this answer





















      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',
      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%2f948897%2fhow-can-i-import-a-database-using-command-line%23new-answer', 'question_page');
      }
      );

      Post as a guest
































      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      5
      down vote



      accepted










      I believe the format is:



      mysql -u username -p database_name < /path/to/file.sql


      From within mysql:



      mysql> use db_name;
      mysql> source backup-file.sql;





      share|improve this answer























      • well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql) and mine (mysql -u root -p spy < /var/www/backup.zip)?
        – stack
        Aug 23 '17 at 6:04






      • 3




        @stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
        – muru
        Aug 23 '17 at 6:08












      • @muru Ah I see. thank you guys. (btw I think you could say so 30min ago :))
        – stack
        Aug 23 '17 at 6:11

















      up vote
      5
      down vote



      accepted










      I believe the format is:



      mysql -u username -p database_name < /path/to/file.sql


      From within mysql:



      mysql> use db_name;
      mysql> source backup-file.sql;





      share|improve this answer























      • well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql) and mine (mysql -u root -p spy < /var/www/backup.zip)?
        – stack
        Aug 23 '17 at 6:04






      • 3




        @stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
        – muru
        Aug 23 '17 at 6:08












      • @muru Ah I see. thank you guys. (btw I think you could say so 30min ago :))
        – stack
        Aug 23 '17 at 6:11















      up vote
      5
      down vote



      accepted







      up vote
      5
      down vote



      accepted






      I believe the format is:



      mysql -u username -p database_name < /path/to/file.sql


      From within mysql:



      mysql> use db_name;
      mysql> source backup-file.sql;





      share|improve this answer














      I believe the format is:



      mysql -u username -p database_name < /path/to/file.sql


      From within mysql:



      mysql> use db_name;
      mysql> source backup-file.sql;






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 23 '17 at 6:07

























      answered Aug 23 '17 at 6:02









      George Udosen

      18.2k94065




      18.2k94065












      • well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql) and mine (mysql -u root -p spy < /var/www/backup.zip)?
        – stack
        Aug 23 '17 at 6:04






      • 3




        @stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
        – muru
        Aug 23 '17 at 6:08












      • @muru Ah I see. thank you guys. (btw I think you could say so 30min ago :))
        – stack
        Aug 23 '17 at 6:11




















      • well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql) and mine (mysql -u root -p spy < /var/www/backup.zip)?
        – stack
        Aug 23 '17 at 6:04






      • 3




        @stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
        – muru
        Aug 23 '17 at 6:08












      • @muru Ah I see. thank you guys. (btw I think you could say so 30min ago :))
        – stack
        Aug 23 '17 at 6:11


















      well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql) and mine (mysql -u root -p spy < /var/www/backup.zip)?
      – stack
      Aug 23 '17 at 6:04




      well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql) and mine (mysql -u root -p spy < /var/www/backup.zip)?
      – stack
      Aug 23 '17 at 6:04




      3




      3




      @stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
      – muru
      Aug 23 '17 at 6:08






      @stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
      – muru
      Aug 23 '17 at 6:08














      @muru Ah I see. thank you guys. (btw I think you could say so 30min ago :))
      – stack
      Aug 23 '17 at 6:11






      @muru Ah I see. thank you guys. (btw I think you could say so 30min ago :))
      – stack
      Aug 23 '17 at 6:11














      up vote
      0
      down vote













      A query normally consists of an SQL statement followed by a semicolon.
      Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:



      mysql> SELECT USER()
      ->


      If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.



      Read more here



      You just need to add the missing semicolon.






      share|improve this answer








      New contributor




      Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        up vote
        0
        down vote













        A query normally consists of an SQL statement followed by a semicolon.
        Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:



        mysql> SELECT USER()
        ->


        If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.



        Read more here



        You just need to add the missing semicolon.






        share|improve this answer








        New contributor




        Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















          up vote
          0
          down vote










          up vote
          0
          down vote









          A query normally consists of an SQL statement followed by a semicolon.
          Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:



          mysql> SELECT USER()
          ->


          If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.



          Read more here



          You just need to add the missing semicolon.






          share|improve this answer








          New contributor




          Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          A query normally consists of an SQL statement followed by a semicolon.
          Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:



          mysql> SELECT USER()
          ->


          If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.



          Read more here



          You just need to add the missing semicolon.







          share|improve this answer








          New contributor




          Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 4 hours ago









          Danijela Kraljević

          1




          1




          New contributor




          Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Danijela Kraljević is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






















              up vote
              0
              down vote













              The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.



              The second issue is that you have a zip file and not a SQL file so you need to unzip it first.



              How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:



              unzip -p /var/www/backup.zip | mysql -u root -p mydb


              unzip -p unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.



              mysql -u root -p mydb is going to prompt you for a password (the -p without a value) and then attempt to pipe in the file data to mydb - change the mydb to your own database. You shouldn't specify the password in the command line as it then remains in your command history.






              share|improve this answer

























                up vote
                0
                down vote













                The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.



                The second issue is that you have a zip file and not a SQL file so you need to unzip it first.



                How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:



                unzip -p /var/www/backup.zip | mysql -u root -p mydb


                unzip -p unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.



                mysql -u root -p mydb is going to prompt you for a password (the -p without a value) and then attempt to pipe in the file data to mydb - change the mydb to your own database. You shouldn't specify the password in the command line as it then remains in your command history.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.



                  The second issue is that you have a zip file and not a SQL file so you need to unzip it first.



                  How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:



                  unzip -p /var/www/backup.zip | mysql -u root -p mydb


                  unzip -p unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.



                  mysql -u root -p mydb is going to prompt you for a password (the -p without a value) and then attempt to pipe in the file data to mydb - change the mydb to your own database. You shouldn't specify the password in the command line as it then remains in your command history.






                  share|improve this answer












                  The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.



                  The second issue is that you have a zip file and not a SQL file so you need to unzip it first.



                  How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:



                  unzip -p /var/www/backup.zip | mysql -u root -p mydb


                  unzip -p unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.



                  mysql -u root -p mydb is going to prompt you for a password (the -p without a value) and then attempt to pipe in the file data to mydb - change the mydb to your own database. You shouldn't specify the password in the command line as it then remains in your command history.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  icc97

                  16627




                  16627






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f948897%2fhow-can-i-import-a-database-using-command-line%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest




















































































                      Popular posts from this blog

                      Ellipse (mathématiques)

                      Quarter-circle Tiles

                      Mont Emei