How to run a .sql file as part of a MySQL Workbench 6.2 query?












2














I'm using MySQL Workbench 6.2 [Windows7] and I want to create a script with all my steps. Among the steps, I have a series of .sql files stored from on my computer that create and populate tables.
I want to run these files from the query tab but every time I use this command:



source C:/Users/[username]/Desktop/sampdb/create_president.sql;



I get an Error 1064, which says




"Error Code: 1064. You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'mysql> source
C:/Users/[username]/Desktop/sampdb/create_president.sql at line 1 "




MySQL nested script nightmare



Can anyone tell me what I'm doing wrong? How can I refer to a .sql file within a MySQL Workbench script?



What code should I use in the MySQL Workbench instead of source? I have tried LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; but it didn't work either. Any idea what can be wrong?



*Just for additional information, create_president.sql contains the following code:



DROP TABLE IF EXISTS president;
#@ _CREATE_TABLE_
CREATE TABLE president
(
last_name VARCHAR(15) NOT NULL,
first_name VARCHAR(15) NOT NULL,
suffix VARCHAR(5) NULL,
city VARCHAR(20) NOT NULL,
state VARCHAR(2) NOT NULL,
birth DATE NOT NULL,
death DATE NULL
);









share|improve this question





























    2














    I'm using MySQL Workbench 6.2 [Windows7] and I want to create a script with all my steps. Among the steps, I have a series of .sql files stored from on my computer that create and populate tables.
    I want to run these files from the query tab but every time I use this command:



    source C:/Users/[username]/Desktop/sampdb/create_president.sql;



    I get an Error 1064, which says




    "Error Code: 1064. You have an error in your
    SQL syntax; check the manual that corresponds to your MySQL server
    version for the right syntax to use near 'mysql> source
    C:/Users/[username]/Desktop/sampdb/create_president.sql at line 1 "




    MySQL nested script nightmare



    Can anyone tell me what I'm doing wrong? How can I refer to a .sql file within a MySQL Workbench script?



    What code should I use in the MySQL Workbench instead of source? I have tried LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; but it didn't work either. Any idea what can be wrong?



    *Just for additional information, create_president.sql contains the following code:



    DROP TABLE IF EXISTS president;
    #@ _CREATE_TABLE_
    CREATE TABLE president
    (
    last_name VARCHAR(15) NOT NULL,
    first_name VARCHAR(15) NOT NULL,
    suffix VARCHAR(5) NULL,
    city VARCHAR(20) NOT NULL,
    state VARCHAR(2) NOT NULL,
    birth DATE NOT NULL,
    death DATE NULL
    );









    share|improve this question



























      2












      2








      2


      1





      I'm using MySQL Workbench 6.2 [Windows7] and I want to create a script with all my steps. Among the steps, I have a series of .sql files stored from on my computer that create and populate tables.
      I want to run these files from the query tab but every time I use this command:



      source C:/Users/[username]/Desktop/sampdb/create_president.sql;



      I get an Error 1064, which says




      "Error Code: 1064. You have an error in your
      SQL syntax; check the manual that corresponds to your MySQL server
      version for the right syntax to use near 'mysql> source
      C:/Users/[username]/Desktop/sampdb/create_president.sql at line 1 "




      MySQL nested script nightmare



      Can anyone tell me what I'm doing wrong? How can I refer to a .sql file within a MySQL Workbench script?



      What code should I use in the MySQL Workbench instead of source? I have tried LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; but it didn't work either. Any idea what can be wrong?



      *Just for additional information, create_president.sql contains the following code:



      DROP TABLE IF EXISTS president;
      #@ _CREATE_TABLE_
      CREATE TABLE president
      (
      last_name VARCHAR(15) NOT NULL,
      first_name VARCHAR(15) NOT NULL,
      suffix VARCHAR(5) NULL,
      city VARCHAR(20) NOT NULL,
      state VARCHAR(2) NOT NULL,
      birth DATE NOT NULL,
      death DATE NULL
      );









      share|improve this question















      I'm using MySQL Workbench 6.2 [Windows7] and I want to create a script with all my steps. Among the steps, I have a series of .sql files stored from on my computer that create and populate tables.
      I want to run these files from the query tab but every time I use this command:



      source C:/Users/[username]/Desktop/sampdb/create_president.sql;



      I get an Error 1064, which says




      "Error Code: 1064. You have an error in your
      SQL syntax; check the manual that corresponds to your MySQL server
      version for the right syntax to use near 'mysql> source
      C:/Users/[username]/Desktop/sampdb/create_president.sql at line 1 "




      MySQL nested script nightmare



      Can anyone tell me what I'm doing wrong? How can I refer to a .sql file within a MySQL Workbench script?



      What code should I use in the MySQL Workbench instead of source? I have tried LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; but it didn't work either. Any idea what can be wrong?



      *Just for additional information, create_president.sql contains the following code:



      DROP TABLE IF EXISTS president;
      #@ _CREATE_TABLE_
      CREATE TABLE president
      (
      last_name VARCHAR(15) NOT NULL,
      first_name VARCHAR(15) NOT NULL,
      suffix VARCHAR(5) NULL,
      city VARCHAR(20) NOT NULL,
      state VARCHAR(2) NOT NULL,
      birth DATE NOT NULL,
      death DATE NULL
      );






      mysql sql mysql-workbench






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '15 at 16:10







      user3507584

















      asked Oct 11 '14 at 19:05









      user3507584user3507584

      1,18911739




      1,18911739
























          3 Answers
          3






          active

          oldest

          votes


















          2














          The source command is a pure (command line) client specific command which MySQL Workbench does not support. Just load the sql file to run it.



          Update (after you edited your question)



          Your SQL file contains DDL. LOAD DATA INFILE however only imports DML. There's no replacement for the MySQL commandline client's SOURCE command. Support for that in MySQL Workbench is however on our todo list.






          share|improve this answer























          • Thanks Mike, sorry if the question is too basic, I am self-learning. I am trying the following but it is not working either. Can you spot what's wrong with it?: LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; That create_president.sql has the following code: DROP TABLE IF EXISTS president; #@ CREATE_TABLE CREATE TABLE president ( last_name VARCHAR(15) NOT NULL, first_name VARCHAR(15) NOT NULL, suffix VARCHAR(5) NULL, city VARCHAR(20) NOT NULL, state VARCHAR(2) NOT NULL, birth DATE NOT NULL, death DATE NULL );
            – user3507584
            Oct 13 '14 at 22:39








          • 1




            This is difficult to read in the comment. Either update your question here or open a new one, where we can take a look.
            – Mike Lischke
            Oct 14 '14 at 6:59










          • Sure Mike, please see the question edited.
            – user3507584
            Oct 14 '14 at 20:39



















          3














          You can run scripts on MySqlWorkBench as follows:



          From the file menu, Select "Run SQL Script".



          enter image description here



          Then, In the popup window, Open the script from your machine.



          enter image description here



          Then Select the schema name which you are going to execute this script. (Previously i created the schema using the command "create database REGISTRY_LOCAL1;")



          enter image description here



          Then execute the script.



          enter image description here






          share|improve this answer































            0














            Just remove the quotes and semicolon. The command source is not SQL and it doesn't like quotes and semicolons. :)



            source /Users/[username]/Documents/company/department.sql





            share|improve this answer





















            • Hi Erico, I tried that but it is not working either :( * I have tried /, // and to separate the filename and still not working. Any other idea?
              – user3507584
              Oct 11 '14 at 19:52










            • *Please see the question I have added a snapshot of MySQL workbench. Thanks for your help!
              – user3507584
              Oct 11 '14 at 19:53











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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%2fstackoverflow.com%2fquestions%2f26318216%2fhow-to-run-a-sql-file-as-part-of-a-mysql-workbench-6-2-query%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            The source command is a pure (command line) client specific command which MySQL Workbench does not support. Just load the sql file to run it.



            Update (after you edited your question)



            Your SQL file contains DDL. LOAD DATA INFILE however only imports DML. There's no replacement for the MySQL commandline client's SOURCE command. Support for that in MySQL Workbench is however on our todo list.






            share|improve this answer























            • Thanks Mike, sorry if the question is too basic, I am self-learning. I am trying the following but it is not working either. Can you spot what's wrong with it?: LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; That create_president.sql has the following code: DROP TABLE IF EXISTS president; #@ CREATE_TABLE CREATE TABLE president ( last_name VARCHAR(15) NOT NULL, first_name VARCHAR(15) NOT NULL, suffix VARCHAR(5) NULL, city VARCHAR(20) NOT NULL, state VARCHAR(2) NOT NULL, birth DATE NOT NULL, death DATE NULL );
              – user3507584
              Oct 13 '14 at 22:39








            • 1




              This is difficult to read in the comment. Either update your question here or open a new one, where we can take a look.
              – Mike Lischke
              Oct 14 '14 at 6:59










            • Sure Mike, please see the question edited.
              – user3507584
              Oct 14 '14 at 20:39
















            2














            The source command is a pure (command line) client specific command which MySQL Workbench does not support. Just load the sql file to run it.



            Update (after you edited your question)



            Your SQL file contains DDL. LOAD DATA INFILE however only imports DML. There's no replacement for the MySQL commandline client's SOURCE command. Support for that in MySQL Workbench is however on our todo list.






            share|improve this answer























            • Thanks Mike, sorry if the question is too basic, I am self-learning. I am trying the following but it is not working either. Can you spot what's wrong with it?: LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; That create_president.sql has the following code: DROP TABLE IF EXISTS president; #@ CREATE_TABLE CREATE TABLE president ( last_name VARCHAR(15) NOT NULL, first_name VARCHAR(15) NOT NULL, suffix VARCHAR(5) NULL, city VARCHAR(20) NOT NULL, state VARCHAR(2) NOT NULL, birth DATE NOT NULL, death DATE NULL );
              – user3507584
              Oct 13 '14 at 22:39








            • 1




              This is difficult to read in the comment. Either update your question here or open a new one, where we can take a look.
              – Mike Lischke
              Oct 14 '14 at 6:59










            • Sure Mike, please see the question edited.
              – user3507584
              Oct 14 '14 at 20:39














            2












            2








            2






            The source command is a pure (command line) client specific command which MySQL Workbench does not support. Just load the sql file to run it.



            Update (after you edited your question)



            Your SQL file contains DDL. LOAD DATA INFILE however only imports DML. There's no replacement for the MySQL commandline client's SOURCE command. Support for that in MySQL Workbench is however on our todo list.






            share|improve this answer














            The source command is a pure (command line) client specific command which MySQL Workbench does not support. Just load the sql file to run it.



            Update (after you edited your question)



            Your SQL file contains DDL. LOAD DATA INFILE however only imports DML. There's no replacement for the MySQL commandline client's SOURCE command. Support for that in MySQL Workbench is however on our todo list.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 28 '18 at 9:26

























            answered Oct 13 '14 at 6:26









            Mike LischkeMike Lischke

            20.7k350102




            20.7k350102












            • Thanks Mike, sorry if the question is too basic, I am self-learning. I am trying the following but it is not working either. Can you spot what's wrong with it?: LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; That create_president.sql has the following code: DROP TABLE IF EXISTS president; #@ CREATE_TABLE CREATE TABLE president ( last_name VARCHAR(15) NOT NULL, first_name VARCHAR(15) NOT NULL, suffix VARCHAR(5) NULL, city VARCHAR(20) NOT NULL, state VARCHAR(2) NOT NULL, birth DATE NOT NULL, death DATE NULL );
              – user3507584
              Oct 13 '14 at 22:39








            • 1




              This is difficult to read in the comment. Either update your question here or open a new one, where we can take a look.
              – Mike Lischke
              Oct 14 '14 at 6:59










            • Sure Mike, please see the question edited.
              – user3507584
              Oct 14 '14 at 20:39


















            • Thanks Mike, sorry if the question is too basic, I am self-learning. I am trying the following but it is not working either. Can you spot what's wrong with it?: LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; That create_president.sql has the following code: DROP TABLE IF EXISTS president; #@ CREATE_TABLE CREATE TABLE president ( last_name VARCHAR(15) NOT NULL, first_name VARCHAR(15) NOT NULL, suffix VARCHAR(5) NULL, city VARCHAR(20) NOT NULL, state VARCHAR(2) NOT NULL, birth DATE NOT NULL, death DATE NULL );
              – user3507584
              Oct 13 '14 at 22:39








            • 1




              This is difficult to read in the comment. Either update your question here or open a new one, where we can take a look.
              – Mike Lischke
              Oct 14 '14 at 6:59










            • Sure Mike, please see the question edited.
              – user3507584
              Oct 14 '14 at 20:39
















            Thanks Mike, sorry if the question is too basic, I am self-learning. I am trying the following but it is not working either. Can you spot what's wrong with it?: LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; That create_president.sql has the following code: DROP TABLE IF EXISTS president; #@ CREATE_TABLE CREATE TABLE president ( last_name VARCHAR(15) NOT NULL, first_name VARCHAR(15) NOT NULL, suffix VARCHAR(5) NULL, city VARCHAR(20) NOT NULL, state VARCHAR(2) NOT NULL, birth DATE NOT NULL, death DATE NULL );
            – user3507584
            Oct 13 '14 at 22:39






            Thanks Mike, sorry if the question is too basic, I am self-learning. I am trying the following but it is not working either. Can you spot what's wrong with it?: LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; That create_president.sql has the following code: DROP TABLE IF EXISTS president; #@ CREATE_TABLE CREATE TABLE president ( last_name VARCHAR(15) NOT NULL, first_name VARCHAR(15) NOT NULL, suffix VARCHAR(5) NULL, city VARCHAR(20) NOT NULL, state VARCHAR(2) NOT NULL, birth DATE NOT NULL, death DATE NULL );
            – user3507584
            Oct 13 '14 at 22:39






            1




            1




            This is difficult to read in the comment. Either update your question here or open a new one, where we can take a look.
            – Mike Lischke
            Oct 14 '14 at 6:59




            This is difficult to read in the comment. Either update your question here or open a new one, where we can take a look.
            – Mike Lischke
            Oct 14 '14 at 6:59












            Sure Mike, please see the question edited.
            – user3507584
            Oct 14 '14 at 20:39




            Sure Mike, please see the question edited.
            – user3507584
            Oct 14 '14 at 20:39













            3














            You can run scripts on MySqlWorkBench as follows:



            From the file menu, Select "Run SQL Script".



            enter image description here



            Then, In the popup window, Open the script from your machine.



            enter image description here



            Then Select the schema name which you are going to execute this script. (Previously i created the schema using the command "create database REGISTRY_LOCAL1;")



            enter image description here



            Then execute the script.



            enter image description here






            share|improve this answer




























              3














              You can run scripts on MySqlWorkBench as follows:



              From the file menu, Select "Run SQL Script".



              enter image description here



              Then, In the popup window, Open the script from your machine.



              enter image description here



              Then Select the schema name which you are going to execute this script. (Previously i created the schema using the command "create database REGISTRY_LOCAL1;")



              enter image description here



              Then execute the script.



              enter image description here






              share|improve this answer


























                3












                3








                3






                You can run scripts on MySqlWorkBench as follows:



                From the file menu, Select "Run SQL Script".



                enter image description here



                Then, In the popup window, Open the script from your machine.



                enter image description here



                Then Select the schema name which you are going to execute this script. (Previously i created the schema using the command "create database REGISTRY_LOCAL1;")



                enter image description here



                Then execute the script.



                enter image description here






                share|improve this answer














                You can run scripts on MySqlWorkBench as follows:



                From the file menu, Select "Run SQL Script".



                enter image description here



                Then, In the popup window, Open the script from your machine.



                enter image description here



                Then Select the schema name which you are going to execute this script. (Previously i created the schema using the command "create database REGISTRY_LOCAL1;")



                enter image description here



                Then execute the script.



                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 19 '16 at 23:03









                Kcoder

                2,40312542




                2,40312542










                answered Dec 19 '16 at 21:49









                Shammi JayasingheShammi Jayasinghe

                412




                412























                    0














                    Just remove the quotes and semicolon. The command source is not SQL and it doesn't like quotes and semicolons. :)



                    source /Users/[username]/Documents/company/department.sql





                    share|improve this answer





















                    • Hi Erico, I tried that but it is not working either :( * I have tried /, // and to separate the filename and still not working. Any other idea?
                      – user3507584
                      Oct 11 '14 at 19:52










                    • *Please see the question I have added a snapshot of MySQL workbench. Thanks for your help!
                      – user3507584
                      Oct 11 '14 at 19:53
















                    0














                    Just remove the quotes and semicolon. The command source is not SQL and it doesn't like quotes and semicolons. :)



                    source /Users/[username]/Documents/company/department.sql





                    share|improve this answer





















                    • Hi Erico, I tried that but it is not working either :( * I have tried /, // and to separate the filename and still not working. Any other idea?
                      – user3507584
                      Oct 11 '14 at 19:52










                    • *Please see the question I have added a snapshot of MySQL workbench. Thanks for your help!
                      – user3507584
                      Oct 11 '14 at 19:53














                    0












                    0








                    0






                    Just remove the quotes and semicolon. The command source is not SQL and it doesn't like quotes and semicolons. :)



                    source /Users/[username]/Documents/company/department.sql





                    share|improve this answer












                    Just remove the quotes and semicolon. The command source is not SQL and it doesn't like quotes and semicolons. :)



                    source /Users/[username]/Documents/company/department.sql






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Oct 11 '14 at 19:42









                    EricoErico

                    728415




                    728415












                    • Hi Erico, I tried that but it is not working either :( * I have tried /, // and to separate the filename and still not working. Any other idea?
                      – user3507584
                      Oct 11 '14 at 19:52










                    • *Please see the question I have added a snapshot of MySQL workbench. Thanks for your help!
                      – user3507584
                      Oct 11 '14 at 19:53


















                    • Hi Erico, I tried that but it is not working either :( * I have tried /, // and to separate the filename and still not working. Any other idea?
                      – user3507584
                      Oct 11 '14 at 19:52










                    • *Please see the question I have added a snapshot of MySQL workbench. Thanks for your help!
                      – user3507584
                      Oct 11 '14 at 19:53
















                    Hi Erico, I tried that but it is not working either :( * I have tried /, // and to separate the filename and still not working. Any other idea?
                    – user3507584
                    Oct 11 '14 at 19:52




                    Hi Erico, I tried that but it is not working either :( * I have tried /, // and to separate the filename and still not working. Any other idea?
                    – user3507584
                    Oct 11 '14 at 19:52












                    *Please see the question I have added a snapshot of MySQL workbench. Thanks for your help!
                    – user3507584
                    Oct 11 '14 at 19:53




                    *Please see the question I have added a snapshot of MySQL workbench. Thanks for your help!
                    – user3507584
                    Oct 11 '14 at 19:53


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2fstackoverflow.com%2fquestions%2f26318216%2fhow-to-run-a-sql-file-as-part-of-a-mysql-workbench-6-2-query%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







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas