MySQL Commands out of sync Python












0















I am trying to initialize my database with MySQL and python mysql connector.
After I run the code bellow I receive this exception:




mysql.connector.errors.DatabaseError: 2014 (HY000): Commands out of sync; you can't run this command now




I tried several thing including commit the connection object although nothing as worked for me.



   def initialization():
cnx = mysql.connector.connect(user="root", password="xxxxxxxxx", host='127.0.0.1')
cursor = cnx.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS izugitdb;")
cursor.execute("USE izugitdb;")
cursor.execute("CREATE TABLE IF NOT EXISTS employee_users (user_id INT AUTO_INCREMENT PRIMARY KEY,username VARCHAR(40) NOT NULL, password VARCHAR(40) NOT NULL,isadmin TINYINT(1) DEFAULT 0 NOT NULL);")
cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")
cursor.execute("CREATE TABLE IF NOT EXISTS clients_workers (id INT AUTO_INCREMENT PRIMARY KEY, worker_id INT ,worker_name VARCHAR(255) NOT NULL, client_id INT);")









share|improve this question

























  • You should consider changing the text of the question a bit, as am pretty sure you might be using this password elsewhere... ;-) Also, it is now a good time to change it wherever you use it.

    – Nikos Steiakakis
    Jan 1 at 9:26











  • I don't think you want a semicolon before declaring your table's engine.

    – khelwood
    Jan 1 at 9:56











  • @delex, if the answer posted below helped solve your problem, you may accept it by clicking on the tick sign beside it, thank you!

    – user5173426
    Feb 7 at 6:19
















0















I am trying to initialize my database with MySQL and python mysql connector.
After I run the code bellow I receive this exception:




mysql.connector.errors.DatabaseError: 2014 (HY000): Commands out of sync; you can't run this command now




I tried several thing including commit the connection object although nothing as worked for me.



   def initialization():
cnx = mysql.connector.connect(user="root", password="xxxxxxxxx", host='127.0.0.1')
cursor = cnx.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS izugitdb;")
cursor.execute("USE izugitdb;")
cursor.execute("CREATE TABLE IF NOT EXISTS employee_users (user_id INT AUTO_INCREMENT PRIMARY KEY,username VARCHAR(40) NOT NULL, password VARCHAR(40) NOT NULL,isadmin TINYINT(1) DEFAULT 0 NOT NULL);")
cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")
cursor.execute("CREATE TABLE IF NOT EXISTS clients_workers (id INT AUTO_INCREMENT PRIMARY KEY, worker_id INT ,worker_name VARCHAR(255) NOT NULL, client_id INT);")









share|improve this question

























  • You should consider changing the text of the question a bit, as am pretty sure you might be using this password elsewhere... ;-) Also, it is now a good time to change it wherever you use it.

    – Nikos Steiakakis
    Jan 1 at 9:26











  • I don't think you want a semicolon before declaring your table's engine.

    – khelwood
    Jan 1 at 9:56











  • @delex, if the answer posted below helped solve your problem, you may accept it by clicking on the tick sign beside it, thank you!

    – user5173426
    Feb 7 at 6:19














0












0








0








I am trying to initialize my database with MySQL and python mysql connector.
After I run the code bellow I receive this exception:




mysql.connector.errors.DatabaseError: 2014 (HY000): Commands out of sync; you can't run this command now




I tried several thing including commit the connection object although nothing as worked for me.



   def initialization():
cnx = mysql.connector.connect(user="root", password="xxxxxxxxx", host='127.0.0.1')
cursor = cnx.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS izugitdb;")
cursor.execute("USE izugitdb;")
cursor.execute("CREATE TABLE IF NOT EXISTS employee_users (user_id INT AUTO_INCREMENT PRIMARY KEY,username VARCHAR(40) NOT NULL, password VARCHAR(40) NOT NULL,isadmin TINYINT(1) DEFAULT 0 NOT NULL);")
cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")
cursor.execute("CREATE TABLE IF NOT EXISTS clients_workers (id INT AUTO_INCREMENT PRIMARY KEY, worker_id INT ,worker_name VARCHAR(255) NOT NULL, client_id INT);")









share|improve this question
















I am trying to initialize my database with MySQL and python mysql connector.
After I run the code bellow I receive this exception:




mysql.connector.errors.DatabaseError: 2014 (HY000): Commands out of sync; you can't run this command now




I tried several thing including commit the connection object although nothing as worked for me.



   def initialization():
cnx = mysql.connector.connect(user="root", password="xxxxxxxxx", host='127.0.0.1')
cursor = cnx.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS izugitdb;")
cursor.execute("USE izugitdb;")
cursor.execute("CREATE TABLE IF NOT EXISTS employee_users (user_id INT AUTO_INCREMENT PRIMARY KEY,username VARCHAR(40) NOT NULL, password VARCHAR(40) NOT NULL,isadmin TINYINT(1) DEFAULT 0 NOT NULL);")
cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")
cursor.execute("CREATE TABLE IF NOT EXISTS clients_workers (id INT AUTO_INCREMENT PRIMARY KEY, worker_id INT ,worker_name VARCHAR(255) NOT NULL, client_id INT);")






python mysql sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 9:54







delex

















asked Jan 1 at 9:21









delexdelex

357




357













  • You should consider changing the text of the question a bit, as am pretty sure you might be using this password elsewhere... ;-) Also, it is now a good time to change it wherever you use it.

    – Nikos Steiakakis
    Jan 1 at 9:26











  • I don't think you want a semicolon before declaring your table's engine.

    – khelwood
    Jan 1 at 9:56











  • @delex, if the answer posted below helped solve your problem, you may accept it by clicking on the tick sign beside it, thank you!

    – user5173426
    Feb 7 at 6:19



















  • You should consider changing the text of the question a bit, as am pretty sure you might be using this password elsewhere... ;-) Also, it is now a good time to change it wherever you use it.

    – Nikos Steiakakis
    Jan 1 at 9:26











  • I don't think you want a semicolon before declaring your table's engine.

    – khelwood
    Jan 1 at 9:56











  • @delex, if the answer posted below helped solve your problem, you may accept it by clicking on the tick sign beside it, thank you!

    – user5173426
    Feb 7 at 6:19

















You should consider changing the text of the question a bit, as am pretty sure you might be using this password elsewhere... ;-) Also, it is now a good time to change it wherever you use it.

– Nikos Steiakakis
Jan 1 at 9:26





You should consider changing the text of the question a bit, as am pretty sure you might be using this password elsewhere... ;-) Also, it is now a good time to change it wherever you use it.

– Nikos Steiakakis
Jan 1 at 9:26













I don't think you want a semicolon before declaring your table's engine.

– khelwood
Jan 1 at 9:56





I don't think you want a semicolon before declaring your table's engine.

– khelwood
Jan 1 at 9:56













@delex, if the answer posted below helped solve your problem, you may accept it by clicking on the tick sign beside it, thank you!

– user5173426
Feb 7 at 6:19





@delex, if the answer posted below helped solve your problem, you may accept it by clicking on the tick sign beside it, thank you!

– user5173426
Feb 7 at 6:19












2 Answers
2






active

oldest

votes


















3














Commands out of sync




If you get Commands out of sync; you can't run this command now in
your client code, you are calling client functions in the wrong order.



This can happen, for example, if you are using mysql_use_result() and
try to execute a new query before you have called mysql_free_result().
It can also happen if you try to execute two queries that return data
without calling mysql_use_result() or mysql_store_result() in between.




Perhaps, the commands in your case, have you tried using them directly in MySQL? and be able to replicate the error?



Or try closing the cursor after each command and then and open it again before using it to execute another statement:



cursor.close() 

cursor = cnx.cursor()


PS. Good catch by @Nikos Steiakakis, I have edited and shaded your password and lets hope that wasn't a real one anyway.






share|improve this answer

































    0














    I Found out that this line



    cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")


    Is making all the trouble, the ENGINE = InnoDB; can't be at the same execute
    Thanks






    share|improve this answer
























    • Yes, it can, just remove the semicolon before the engine keyword. It is part of the create statement.

      – Shadow
      Jan 1 at 10:58











    • @Shadow great, you should consider closing this answer by accepting an answer! cheers

      – user5173426
      Jan 4 at 6:12











    • @user5173426 I'm not the OP

      – Shadow
      Jan 4 at 7:41











    • @Shadow Oops, my bad. too much caffeine lately.

      – user5173426
      Jan 4 at 14:08











    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%2f53994303%2fmysql-commands-out-of-sync-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Commands out of sync




    If you get Commands out of sync; you can't run this command now in
    your client code, you are calling client functions in the wrong order.



    This can happen, for example, if you are using mysql_use_result() and
    try to execute a new query before you have called mysql_free_result().
    It can also happen if you try to execute two queries that return data
    without calling mysql_use_result() or mysql_store_result() in between.




    Perhaps, the commands in your case, have you tried using them directly in MySQL? and be able to replicate the error?



    Or try closing the cursor after each command and then and open it again before using it to execute another statement:



    cursor.close() 

    cursor = cnx.cursor()


    PS. Good catch by @Nikos Steiakakis, I have edited and shaded your password and lets hope that wasn't a real one anyway.






    share|improve this answer






























      3














      Commands out of sync




      If you get Commands out of sync; you can't run this command now in
      your client code, you are calling client functions in the wrong order.



      This can happen, for example, if you are using mysql_use_result() and
      try to execute a new query before you have called mysql_free_result().
      It can also happen if you try to execute two queries that return data
      without calling mysql_use_result() or mysql_store_result() in between.




      Perhaps, the commands in your case, have you tried using them directly in MySQL? and be able to replicate the error?



      Or try closing the cursor after each command and then and open it again before using it to execute another statement:



      cursor.close() 

      cursor = cnx.cursor()


      PS. Good catch by @Nikos Steiakakis, I have edited and shaded your password and lets hope that wasn't a real one anyway.






      share|improve this answer




























        3












        3








        3







        Commands out of sync




        If you get Commands out of sync; you can't run this command now in
        your client code, you are calling client functions in the wrong order.



        This can happen, for example, if you are using mysql_use_result() and
        try to execute a new query before you have called mysql_free_result().
        It can also happen if you try to execute two queries that return data
        without calling mysql_use_result() or mysql_store_result() in between.




        Perhaps, the commands in your case, have you tried using them directly in MySQL? and be able to replicate the error?



        Or try closing the cursor after each command and then and open it again before using it to execute another statement:



        cursor.close() 

        cursor = cnx.cursor()


        PS. Good catch by @Nikos Steiakakis, I have edited and shaded your password and lets hope that wasn't a real one anyway.






        share|improve this answer















        Commands out of sync




        If you get Commands out of sync; you can't run this command now in
        your client code, you are calling client functions in the wrong order.



        This can happen, for example, if you are using mysql_use_result() and
        try to execute a new query before you have called mysql_free_result().
        It can also happen if you try to execute two queries that return data
        without calling mysql_use_result() or mysql_store_result() in between.




        Perhaps, the commands in your case, have you tried using them directly in MySQL? and be able to replicate the error?



        Or try closing the cursor after each command and then and open it again before using it to execute another statement:



        cursor.close() 

        cursor = cnx.cursor()


        PS. Good catch by @Nikos Steiakakis, I have edited and shaded your password and lets hope that wasn't a real one anyway.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 9:32

























        answered Jan 1 at 9:24









        user5173426user5173426

        7,20421338




        7,20421338

























            0














            I Found out that this line



            cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")


            Is making all the trouble, the ENGINE = InnoDB; can't be at the same execute
            Thanks






            share|improve this answer
























            • Yes, it can, just remove the semicolon before the engine keyword. It is part of the create statement.

              – Shadow
              Jan 1 at 10:58











            • @Shadow great, you should consider closing this answer by accepting an answer! cheers

              – user5173426
              Jan 4 at 6:12











            • @user5173426 I'm not the OP

              – Shadow
              Jan 4 at 7:41











            • @Shadow Oops, my bad. too much caffeine lately.

              – user5173426
              Jan 4 at 14:08
















            0














            I Found out that this line



            cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")


            Is making all the trouble, the ENGINE = InnoDB; can't be at the same execute
            Thanks






            share|improve this answer
























            • Yes, it can, just remove the semicolon before the engine keyword. It is part of the create statement.

              – Shadow
              Jan 1 at 10:58











            • @Shadow great, you should consider closing this answer by accepting an answer! cheers

              – user5173426
              Jan 4 at 6:12











            • @user5173426 I'm not the OP

              – Shadow
              Jan 4 at 7:41











            • @Shadow Oops, my bad. too much caffeine lately.

              – user5173426
              Jan 4 at 14:08














            0












            0








            0







            I Found out that this line



            cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")


            Is making all the trouble, the ENGINE = InnoDB; can't be at the same execute
            Thanks






            share|improve this answer













            I Found out that this line



            cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")


            Is making all the trouble, the ENGINE = InnoDB; can't be at the same execute
            Thanks







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 1 at 9:53









            delexdelex

            357




            357













            • Yes, it can, just remove the semicolon before the engine keyword. It is part of the create statement.

              – Shadow
              Jan 1 at 10:58











            • @Shadow great, you should consider closing this answer by accepting an answer! cheers

              – user5173426
              Jan 4 at 6:12











            • @user5173426 I'm not the OP

              – Shadow
              Jan 4 at 7:41











            • @Shadow Oops, my bad. too much caffeine lately.

              – user5173426
              Jan 4 at 14:08



















            • Yes, it can, just remove the semicolon before the engine keyword. It is part of the create statement.

              – Shadow
              Jan 1 at 10:58











            • @Shadow great, you should consider closing this answer by accepting an answer! cheers

              – user5173426
              Jan 4 at 6:12











            • @user5173426 I'm not the OP

              – Shadow
              Jan 4 at 7:41











            • @Shadow Oops, my bad. too much caffeine lately.

              – user5173426
              Jan 4 at 14:08

















            Yes, it can, just remove the semicolon before the engine keyword. It is part of the create statement.

            – Shadow
            Jan 1 at 10:58





            Yes, it can, just remove the semicolon before the engine keyword. It is part of the create statement.

            – Shadow
            Jan 1 at 10:58













            @Shadow great, you should consider closing this answer by accepting an answer! cheers

            – user5173426
            Jan 4 at 6:12





            @Shadow great, you should consider closing this answer by accepting an answer! cheers

            – user5173426
            Jan 4 at 6:12













            @user5173426 I'm not the OP

            – Shadow
            Jan 4 at 7:41





            @user5173426 I'm not the OP

            – Shadow
            Jan 4 at 7:41













            @Shadow Oops, my bad. too much caffeine lately.

            – user5173426
            Jan 4 at 14:08





            @Shadow Oops, my bad. too much caffeine lately.

            – user5173426
            Jan 4 at 14:08


















            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994303%2fmysql-commands-out-of-sync-python%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

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas

            Can't read property showImagePicker of undefined in react native iOS