Get the sql query result without extra symbols or characters using batch?












1















Like --disable-column-names option, do we have an option to get the sql query result in text file without having the extra symbols or characters?



for example



mysql -u username -ppassword  --disable-column-names --execute "select rules from test">out.txt


i used above to get the result .but in my test table contains below rules



    ---------------------------------------------------------------------
rules
---------------------------------------------------------------------
select no from tabl1
select name from tabl2 innerjoin select name from tabl3
select id from tabl6
select card from tabl3
--------------------------------------------------------------------


here is script i used which already mentioned above



mysql -u username -ppassword  --disable-column-names --execute "select rules from test">out.txt


when i used above query i get result like



    select no/n from tabl1
select name/n from tabl2/n innerjoin/n select name/n from tabl3
select id/n from tabl6
select card/n from tabl3


is that any way to avoid this problem..i dont want special charcter like'/n ' in my text file?










share|improve this question



























    1















    Like --disable-column-names option, do we have an option to get the sql query result in text file without having the extra symbols or characters?



    for example



    mysql -u username -ppassword  --disable-column-names --execute "select rules from test">out.txt


    i used above to get the result .but in my test table contains below rules



        ---------------------------------------------------------------------
    rules
    ---------------------------------------------------------------------
    select no from tabl1
    select name from tabl2 innerjoin select name from tabl3
    select id from tabl6
    select card from tabl3
    --------------------------------------------------------------------


    here is script i used which already mentioned above



    mysql -u username -ppassword  --disable-column-names --execute "select rules from test">out.txt


    when i used above query i get result like



        select no/n from tabl1
    select name/n from tabl2/n innerjoin/n select name/n from tabl3
    select id/n from tabl6
    select card/n from tabl3


    is that any way to avoid this problem..i dont want special charcter like'/n ' in my text file?










    share|improve this question

























      1












      1








      1








      Like --disable-column-names option, do we have an option to get the sql query result in text file without having the extra symbols or characters?



      for example



      mysql -u username -ppassword  --disable-column-names --execute "select rules from test">out.txt


      i used above to get the result .but in my test table contains below rules



          ---------------------------------------------------------------------
      rules
      ---------------------------------------------------------------------
      select no from tabl1
      select name from tabl2 innerjoin select name from tabl3
      select id from tabl6
      select card from tabl3
      --------------------------------------------------------------------


      here is script i used which already mentioned above



      mysql -u username -ppassword  --disable-column-names --execute "select rules from test">out.txt


      when i used above query i get result like



          select no/n from tabl1
      select name/n from tabl2/n innerjoin/n select name/n from tabl3
      select id/n from tabl6
      select card/n from tabl3


      is that any way to avoid this problem..i dont want special charcter like'/n ' in my text file?










      share|improve this question














      Like --disable-column-names option, do we have an option to get the sql query result in text file without having the extra symbols or characters?



      for example



      mysql -u username -ppassword  --disable-column-names --execute "select rules from test">out.txt


      i used above to get the result .but in my test table contains below rules



          ---------------------------------------------------------------------
      rules
      ---------------------------------------------------------------------
      select no from tabl1
      select name from tabl2 innerjoin select name from tabl3
      select id from tabl6
      select card from tabl3
      --------------------------------------------------------------------


      here is script i used which already mentioned above



      mysql -u username -ppassword  --disable-column-names --execute "select rules from test">out.txt


      when i used above query i get result like



          select no/n from tabl1
      select name/n from tabl2/n innerjoin/n select name/n from tabl3
      select id/n from tabl6
      select card/n from tabl3


      is that any way to avoid this problem..i dont want special charcter like'/n ' in my text file?







      batch batch-file mysql sql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 25 at 13:08









      seepana avinashseepana avinash

      425




      425






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Export MySQL Query Results to a File using Command Line



          I performed this and I didn't get the /n characters so I'm not sure what's up with that. Perhaps the actual query results that are returned is the text content of the select statements and those /n characters are part of that content. I mention this because you say your results are the select statements with those characters.



          Another solution you could use is SELECT INTO OUTFILE with a syntax such as . . .





          • select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1





            1. With this you could execute this logic at the mysql command line as such:




              mysql -u username -ppassword --execute "select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1"




            2. Otherwise you could put the logic into a stored procedure and accept the full file path as the first parameter passed to it at run time and execute it from the mysql command line that way.




              mysql -u username -ppassword --execute "CALL StoredProcName('C:/Folder/Path/out.txt')"






          Note: For the full folder path that you specify which MySQL will utilize, be sure to use either a single forward slash (/) or else you double backslashes (\) which separate folders and the file because the single backslash () is a MySQL escape character.





          Further Resources





          • SELECT INTO OUTFILE


            Description



            SELECT ... INTO OUTFILE writes the resulting rows to a file, and
            allows the use of column and row terminators to specify a particular
            output format. The default is to terminate fields with tabs (t) and
            lines with newlines (n).



            The file must not exist. It cannot be overwritten. A user needs the
            FILE privilege to run this statement. Also, MariaDB needs permission
            to write files in the specified location. If the secure_file_priv
            system variable is set to a non-empty directory name, the file can
            only be written to that directory.



            The CHARACTER SET clause specifies the character set in which the
            results are to be written. Without the clause, no conversion takes
            place (the binary character set). In this case, if there are multiple
            character sets, the output will contain these too, and may not easily
            be able to be reloaded.



            Source









          share|improve this answer


























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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%2fsuperuser.com%2fquestions%2f1398355%2fget-the-sql-query-result-without-extra-symbols-or-characters-using-batch%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Export MySQL Query Results to a File using Command Line



            I performed this and I didn't get the /n characters so I'm not sure what's up with that. Perhaps the actual query results that are returned is the text content of the select statements and those /n characters are part of that content. I mention this because you say your results are the select statements with those characters.



            Another solution you could use is SELECT INTO OUTFILE with a syntax such as . . .





            • select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1





              1. With this you could execute this logic at the mysql command line as such:




                mysql -u username -ppassword --execute "select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1"




              2. Otherwise you could put the logic into a stored procedure and accept the full file path as the first parameter passed to it at run time and execute it from the mysql command line that way.




                mysql -u username -ppassword --execute "CALL StoredProcName('C:/Folder/Path/out.txt')"






            Note: For the full folder path that you specify which MySQL will utilize, be sure to use either a single forward slash (/) or else you double backslashes (\) which separate folders and the file because the single backslash () is a MySQL escape character.





            Further Resources





            • SELECT INTO OUTFILE


              Description



              SELECT ... INTO OUTFILE writes the resulting rows to a file, and
              allows the use of column and row terminators to specify a particular
              output format. The default is to terminate fields with tabs (t) and
              lines with newlines (n).



              The file must not exist. It cannot be overwritten. A user needs the
              FILE privilege to run this statement. Also, MariaDB needs permission
              to write files in the specified location. If the secure_file_priv
              system variable is set to a non-empty directory name, the file can
              only be written to that directory.



              The CHARACTER SET clause specifies the character set in which the
              results are to be written. Without the clause, no conversion takes
              place (the binary character set). In this case, if there are multiple
              character sets, the output will contain these too, and may not easily
              be able to be reloaded.



              Source









            share|improve this answer






























              2














              Export MySQL Query Results to a File using Command Line



              I performed this and I didn't get the /n characters so I'm not sure what's up with that. Perhaps the actual query results that are returned is the text content of the select statements and those /n characters are part of that content. I mention this because you say your results are the select statements with those characters.



              Another solution you could use is SELECT INTO OUTFILE with a syntax such as . . .





              • select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1





                1. With this you could execute this logic at the mysql command line as such:




                  mysql -u username -ppassword --execute "select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1"




                2. Otherwise you could put the logic into a stored procedure and accept the full file path as the first parameter passed to it at run time and execute it from the mysql command line that way.




                  mysql -u username -ppassword --execute "CALL StoredProcName('C:/Folder/Path/out.txt')"






              Note: For the full folder path that you specify which MySQL will utilize, be sure to use either a single forward slash (/) or else you double backslashes (\) which separate folders and the file because the single backslash () is a MySQL escape character.





              Further Resources





              • SELECT INTO OUTFILE


                Description



                SELECT ... INTO OUTFILE writes the resulting rows to a file, and
                allows the use of column and row terminators to specify a particular
                output format. The default is to terminate fields with tabs (t) and
                lines with newlines (n).



                The file must not exist. It cannot be overwritten. A user needs the
                FILE privilege to run this statement. Also, MariaDB needs permission
                to write files in the specified location. If the secure_file_priv
                system variable is set to a non-empty directory name, the file can
                only be written to that directory.



                The CHARACTER SET clause specifies the character set in which the
                results are to be written. Without the clause, no conversion takes
                place (the binary character set). In this case, if there are multiple
                character sets, the output will contain these too, and may not easily
                be able to be reloaded.



                Source









              share|improve this answer




























                2












                2








                2







                Export MySQL Query Results to a File using Command Line



                I performed this and I didn't get the /n characters so I'm not sure what's up with that. Perhaps the actual query results that are returned is the text content of the select statements and those /n characters are part of that content. I mention this because you say your results are the select statements with those characters.



                Another solution you could use is SELECT INTO OUTFILE with a syntax such as . . .





                • select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1





                  1. With this you could execute this logic at the mysql command line as such:




                    mysql -u username -ppassword --execute "select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1"




                  2. Otherwise you could put the logic into a stored procedure and accept the full file path as the first parameter passed to it at run time and execute it from the mysql command line that way.




                    mysql -u username -ppassword --execute "CALL StoredProcName('C:/Folder/Path/out.txt')"






                Note: For the full folder path that you specify which MySQL will utilize, be sure to use either a single forward slash (/) or else you double backslashes (\) which separate folders and the file because the single backslash () is a MySQL escape character.





                Further Resources





                • SELECT INTO OUTFILE


                  Description



                  SELECT ... INTO OUTFILE writes the resulting rows to a file, and
                  allows the use of column and row terminators to specify a particular
                  output format. The default is to terminate fields with tabs (t) and
                  lines with newlines (n).



                  The file must not exist. It cannot be overwritten. A user needs the
                  FILE privilege to run this statement. Also, MariaDB needs permission
                  to write files in the specified location. If the secure_file_priv
                  system variable is set to a non-empty directory name, the file can
                  only be written to that directory.



                  The CHARACTER SET clause specifies the character set in which the
                  results are to be written. Without the clause, no conversion takes
                  place (the binary character set). In this case, if there are multiple
                  character sets, the output will contain these too, and may not easily
                  be able to be reloaded.



                  Source









                share|improve this answer















                Export MySQL Query Results to a File using Command Line



                I performed this and I didn't get the /n characters so I'm not sure what's up with that. Perhaps the actual query results that are returned is the text content of the select statements and those /n characters are part of that content. I mention this because you say your results are the select statements with those characters.



                Another solution you could use is SELECT INTO OUTFILE with a syntax such as . . .





                • select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1





                  1. With this you could execute this logic at the mysql command line as such:




                    mysql -u username -ppassword --execute "select no INTO OUTFILE 'C:/Folder/Path/out.txt' from tabl1"




                  2. Otherwise you could put the logic into a stored procedure and accept the full file path as the first parameter passed to it at run time and execute it from the mysql command line that way.




                    mysql -u username -ppassword --execute "CALL StoredProcName('C:/Folder/Path/out.txt')"






                Note: For the full folder path that you specify which MySQL will utilize, be sure to use either a single forward slash (/) or else you double backslashes (\) which separate folders and the file because the single backslash () is a MySQL escape character.





                Further Resources





                • SELECT INTO OUTFILE


                  Description



                  SELECT ... INTO OUTFILE writes the resulting rows to a file, and
                  allows the use of column and row terminators to specify a particular
                  output format. The default is to terminate fields with tabs (t) and
                  lines with newlines (n).



                  The file must not exist. It cannot be overwritten. A user needs the
                  FILE privilege to run this statement. Also, MariaDB needs permission
                  to write files in the specified location. If the secure_file_priv
                  system variable is set to a non-empty directory name, the file can
                  only be written to that directory.



                  The CHARACTER SET clause specifies the character set in which the
                  results are to be written. Without the clause, no conversion takes
                  place (the binary character set). In this case, if there are multiple
                  character sets, the output will contain these too, and may not easily
                  be able to be reloaded.



                  Source










                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 13 at 2:03

























                answered Jan 27 at 0:15









                Pimp Juice ITPimp Juice IT

                25.2k114177




                25.2k114177






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • 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%2fsuperuser.com%2fquestions%2f1398355%2fget-the-sql-query-result-without-extra-symbols-or-characters-using-batch%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

                    If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                    Alcedinidae

                    Can an atomic nucleus contain both particles and antiparticles? [duplicate]