Incorrect String Value in MySQL db












-3














I am running a webapp on Ubuntu 16.04.4.
The stack is as follows



Python 3.5.2

MySQL 5.7.22

Flask

Flask-SQLAlchemy



The webapp has a feature for admins to upload some text using a xlsx. file which is read with openpyxl inside the webapp. However while saving I am getting errors like:



sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (1366, "Incorrect string value: '\xC4\x9B nep...' 


In the beginning I was able to delete the characters which were making troubles (e.g. zero width whitespace). But now I am not able to do it anymore like this.



Reading a bit on the internet I think it could be that my db is not using utf8mb4. Could someone lead me to update my db and all its tables? Because I do not know anything about SQL and stuff.
As the webapp is used in production I do not like to try tutorials which are outdated.










share|improve this question



























    -3














    I am running a webapp on Ubuntu 16.04.4.
    The stack is as follows



    Python 3.5.2

    MySQL 5.7.22

    Flask

    Flask-SQLAlchemy



    The webapp has a feature for admins to upload some text using a xlsx. file which is read with openpyxl inside the webapp. However while saving I am getting errors like:



    sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (1366, "Incorrect string value: '\xC4\x9B nep...' 


    In the beginning I was able to delete the characters which were making troubles (e.g. zero width whitespace). But now I am not able to do it anymore like this.



    Reading a bit on the internet I think it could be that my db is not using utf8mb4. Could someone lead me to update my db and all its tables? Because I do not know anything about SQL and stuff.
    As the webapp is used in production I do not like to try tutorials which are outdated.










    share|improve this question

























      -3












      -3








      -3







      I am running a webapp on Ubuntu 16.04.4.
      The stack is as follows



      Python 3.5.2

      MySQL 5.7.22

      Flask

      Flask-SQLAlchemy



      The webapp has a feature for admins to upload some text using a xlsx. file which is read with openpyxl inside the webapp. However while saving I am getting errors like:



      sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (1366, "Incorrect string value: '\xC4\x9B nep...' 


      In the beginning I was able to delete the characters which were making troubles (e.g. zero width whitespace). But now I am not able to do it anymore like this.



      Reading a bit on the internet I think it could be that my db is not using utf8mb4. Could someone lead me to update my db and all its tables? Because I do not know anything about SQL and stuff.
      As the webapp is used in production I do not like to try tutorials which are outdated.










      share|improve this question













      I am running a webapp on Ubuntu 16.04.4.
      The stack is as follows



      Python 3.5.2

      MySQL 5.7.22

      Flask

      Flask-SQLAlchemy



      The webapp has a feature for admins to upload some text using a xlsx. file which is read with openpyxl inside the webapp. However while saving I am getting errors like:



      sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (1366, "Incorrect string value: '\xC4\x9B nep...' 


      In the beginning I was able to delete the characters which were making troubles (e.g. zero width whitespace). But now I am not able to do it anymore like this.



      Reading a bit on the internet I think it could be that my db is not using utf8mb4. Could someone lead me to update my db and all its tables? Because I do not know anything about SQL and stuff.
      As the webapp is used in production I do not like to try tutorials which are outdated.







      mysql ubuntu encoding sqlalchemy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 21:12









      WTRipper

      304




      304
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Seems to work now. I did following steps:




          1. Started the mysql cli with:
            mysql -u root -p

          2. Logged in using the root pw.


          3. Checked the default parameters using
            show variables like "%character%";
            which gave me:



            +--------------------------+----------------------------+
            | Variable_name | Value |
            +--------------------------+----------------------------+
            | character_set_client | utf8 |
            | character_set_connection | utf8 |
            | character_set_database | latin1 |
            | character_set_filesystem | binary |
            | character_set_results | utf8 |
            | character_set_server | latin1 |
            | character_set_system | utf8 |
            | character_sets_dir | /usr/share/mysql/charsets/ |
            +--------------------------+----------------------------+


            and
            show variables like "%collation%";
            which gave me



            +----------------------+-------------------+
            | Variable_name | Value |
            +----------------------+-------------------+
            | collation_connection | utf8_general_ci |
            | collation_database | latin1_swedish_ci |
            | collation_server | latin1_swedish_ci |
            +----------------------+-------------------+



          4. So I edited /etc/mysql/my.cnf
            I added:



            [client]
            default-character-set = utf8mb4

            [mysql]
            default-character-set = utf8mb4

            [mysqld]
            character-set-server = utf8mb4
            collation-server = utf8mb4_unicode_ci



          5. Restarting mysql (sudo service mysql restart) and running the same commands as above now gave me



            +--------------------------+----------------------------+
            | Variable_name | Value |
            +--------------------------+----------------------------+
            | character_set_client | utf8mb4 |
            | character_set_connection | utf8mb4 |
            | character_set_database | utf8mb4 |
            | character_set_filesystem | binary |
            | character_set_results | utf8mb4 |
            | character_set_server | utf8mb4 |
            | character_set_system | utf8 |
            | character_sets_dir | /usr/share/mysql/charsets/ |
            +--------------------------+----------------------------+


            and



            +----------------------+--------------------+
            | Variable_name | Value |
            +----------------------+--------------------+
            | collation_connection | utf8mb4_general_ci |
            | collation_database | utf8mb4_unicode_ci |
            | collation_server | utf8mb4_unicode_ci |
            +----------------------+--------------------+


          6. So I looked up the table settings using
            SHOW TABLE STATUS FROM databasename;
            They still used stuff like latin1_swedish_ci



          7. I used following to change the database setting:
            ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
            and following for each table:



            use databasename;
            ALTER TABLE assessments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;



            1. Looking up again the table settings showed that latin1_swedish_ci was now changed to utf8mb4_unicode_ci

            2. Then I changed the sqlalchemy connection url to use ?encoding=utf8mb4 at the end.

            3. Restarted mysql again and the webapp. Since then it's working properly.








          share|improve this answer





















            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%2f53401602%2fincorrect-string-value-in-mysql-db%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









            0














            Seems to work now. I did following steps:




            1. Started the mysql cli with:
              mysql -u root -p

            2. Logged in using the root pw.


            3. Checked the default parameters using
              show variables like "%character%";
              which gave me:



              +--------------------------+----------------------------+
              | Variable_name | Value |
              +--------------------------+----------------------------+
              | character_set_client | utf8 |
              | character_set_connection | utf8 |
              | character_set_database | latin1 |
              | character_set_filesystem | binary |
              | character_set_results | utf8 |
              | character_set_server | latin1 |
              | character_set_system | utf8 |
              | character_sets_dir | /usr/share/mysql/charsets/ |
              +--------------------------+----------------------------+


              and
              show variables like "%collation%";
              which gave me



              +----------------------+-------------------+
              | Variable_name | Value |
              +----------------------+-------------------+
              | collation_connection | utf8_general_ci |
              | collation_database | latin1_swedish_ci |
              | collation_server | latin1_swedish_ci |
              +----------------------+-------------------+



            4. So I edited /etc/mysql/my.cnf
              I added:



              [client]
              default-character-set = utf8mb4

              [mysql]
              default-character-set = utf8mb4

              [mysqld]
              character-set-server = utf8mb4
              collation-server = utf8mb4_unicode_ci



            5. Restarting mysql (sudo service mysql restart) and running the same commands as above now gave me



              +--------------------------+----------------------------+
              | Variable_name | Value |
              +--------------------------+----------------------------+
              | character_set_client | utf8mb4 |
              | character_set_connection | utf8mb4 |
              | character_set_database | utf8mb4 |
              | character_set_filesystem | binary |
              | character_set_results | utf8mb4 |
              | character_set_server | utf8mb4 |
              | character_set_system | utf8 |
              | character_sets_dir | /usr/share/mysql/charsets/ |
              +--------------------------+----------------------------+


              and



              +----------------------+--------------------+
              | Variable_name | Value |
              +----------------------+--------------------+
              | collation_connection | utf8mb4_general_ci |
              | collation_database | utf8mb4_unicode_ci |
              | collation_server | utf8mb4_unicode_ci |
              +----------------------+--------------------+


            6. So I looked up the table settings using
              SHOW TABLE STATUS FROM databasename;
              They still used stuff like latin1_swedish_ci



            7. I used following to change the database setting:
              ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
              and following for each table:



              use databasename;
              ALTER TABLE assessments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;



              1. Looking up again the table settings showed that latin1_swedish_ci was now changed to utf8mb4_unicode_ci

              2. Then I changed the sqlalchemy connection url to use ?encoding=utf8mb4 at the end.

              3. Restarted mysql again and the webapp. Since then it's working properly.








            share|improve this answer


























              0














              Seems to work now. I did following steps:




              1. Started the mysql cli with:
                mysql -u root -p

              2. Logged in using the root pw.


              3. Checked the default parameters using
                show variables like "%character%";
                which gave me:



                +--------------------------+----------------------------+
                | Variable_name | Value |
                +--------------------------+----------------------------+
                | character_set_client | utf8 |
                | character_set_connection | utf8 |
                | character_set_database | latin1 |
                | character_set_filesystem | binary |
                | character_set_results | utf8 |
                | character_set_server | latin1 |
                | character_set_system | utf8 |
                | character_sets_dir | /usr/share/mysql/charsets/ |
                +--------------------------+----------------------------+


                and
                show variables like "%collation%";
                which gave me



                +----------------------+-------------------+
                | Variable_name | Value |
                +----------------------+-------------------+
                | collation_connection | utf8_general_ci |
                | collation_database | latin1_swedish_ci |
                | collation_server | latin1_swedish_ci |
                +----------------------+-------------------+



              4. So I edited /etc/mysql/my.cnf
                I added:



                [client]
                default-character-set = utf8mb4

                [mysql]
                default-character-set = utf8mb4

                [mysqld]
                character-set-server = utf8mb4
                collation-server = utf8mb4_unicode_ci



              5. Restarting mysql (sudo service mysql restart) and running the same commands as above now gave me



                +--------------------------+----------------------------+
                | Variable_name | Value |
                +--------------------------+----------------------------+
                | character_set_client | utf8mb4 |
                | character_set_connection | utf8mb4 |
                | character_set_database | utf8mb4 |
                | character_set_filesystem | binary |
                | character_set_results | utf8mb4 |
                | character_set_server | utf8mb4 |
                | character_set_system | utf8 |
                | character_sets_dir | /usr/share/mysql/charsets/ |
                +--------------------------+----------------------------+


                and



                +----------------------+--------------------+
                | Variable_name | Value |
                +----------------------+--------------------+
                | collation_connection | utf8mb4_general_ci |
                | collation_database | utf8mb4_unicode_ci |
                | collation_server | utf8mb4_unicode_ci |
                +----------------------+--------------------+


              6. So I looked up the table settings using
                SHOW TABLE STATUS FROM databasename;
                They still used stuff like latin1_swedish_ci



              7. I used following to change the database setting:
                ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
                and following for each table:



                use databasename;
                ALTER TABLE assessments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;



                1. Looking up again the table settings showed that latin1_swedish_ci was now changed to utf8mb4_unicode_ci

                2. Then I changed the sqlalchemy connection url to use ?encoding=utf8mb4 at the end.

                3. Restarted mysql again and the webapp. Since then it's working properly.








              share|improve this answer
























                0












                0








                0






                Seems to work now. I did following steps:




                1. Started the mysql cli with:
                  mysql -u root -p

                2. Logged in using the root pw.


                3. Checked the default parameters using
                  show variables like "%character%";
                  which gave me:



                  +--------------------------+----------------------------+
                  | Variable_name | Value |
                  +--------------------------+----------------------------+
                  | character_set_client | utf8 |
                  | character_set_connection | utf8 |
                  | character_set_database | latin1 |
                  | character_set_filesystem | binary |
                  | character_set_results | utf8 |
                  | character_set_server | latin1 |
                  | character_set_system | utf8 |
                  | character_sets_dir | /usr/share/mysql/charsets/ |
                  +--------------------------+----------------------------+


                  and
                  show variables like "%collation%";
                  which gave me



                  +----------------------+-------------------+
                  | Variable_name | Value |
                  +----------------------+-------------------+
                  | collation_connection | utf8_general_ci |
                  | collation_database | latin1_swedish_ci |
                  | collation_server | latin1_swedish_ci |
                  +----------------------+-------------------+



                4. So I edited /etc/mysql/my.cnf
                  I added:



                  [client]
                  default-character-set = utf8mb4

                  [mysql]
                  default-character-set = utf8mb4

                  [mysqld]
                  character-set-server = utf8mb4
                  collation-server = utf8mb4_unicode_ci



                5. Restarting mysql (sudo service mysql restart) and running the same commands as above now gave me



                  +--------------------------+----------------------------+
                  | Variable_name | Value |
                  +--------------------------+----------------------------+
                  | character_set_client | utf8mb4 |
                  | character_set_connection | utf8mb4 |
                  | character_set_database | utf8mb4 |
                  | character_set_filesystem | binary |
                  | character_set_results | utf8mb4 |
                  | character_set_server | utf8mb4 |
                  | character_set_system | utf8 |
                  | character_sets_dir | /usr/share/mysql/charsets/ |
                  +--------------------------+----------------------------+


                  and



                  +----------------------+--------------------+
                  | Variable_name | Value |
                  +----------------------+--------------------+
                  | collation_connection | utf8mb4_general_ci |
                  | collation_database | utf8mb4_unicode_ci |
                  | collation_server | utf8mb4_unicode_ci |
                  +----------------------+--------------------+


                6. So I looked up the table settings using
                  SHOW TABLE STATUS FROM databasename;
                  They still used stuff like latin1_swedish_ci



                7. I used following to change the database setting:
                  ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
                  and following for each table:



                  use databasename;
                  ALTER TABLE assessments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;



                  1. Looking up again the table settings showed that latin1_swedish_ci was now changed to utf8mb4_unicode_ci

                  2. Then I changed the sqlalchemy connection url to use ?encoding=utf8mb4 at the end.

                  3. Restarted mysql again and the webapp. Since then it's working properly.








                share|improve this answer












                Seems to work now. I did following steps:




                1. Started the mysql cli with:
                  mysql -u root -p

                2. Logged in using the root pw.


                3. Checked the default parameters using
                  show variables like "%character%";
                  which gave me:



                  +--------------------------+----------------------------+
                  | Variable_name | Value |
                  +--------------------------+----------------------------+
                  | character_set_client | utf8 |
                  | character_set_connection | utf8 |
                  | character_set_database | latin1 |
                  | character_set_filesystem | binary |
                  | character_set_results | utf8 |
                  | character_set_server | latin1 |
                  | character_set_system | utf8 |
                  | character_sets_dir | /usr/share/mysql/charsets/ |
                  +--------------------------+----------------------------+


                  and
                  show variables like "%collation%";
                  which gave me



                  +----------------------+-------------------+
                  | Variable_name | Value |
                  +----------------------+-------------------+
                  | collation_connection | utf8_general_ci |
                  | collation_database | latin1_swedish_ci |
                  | collation_server | latin1_swedish_ci |
                  +----------------------+-------------------+



                4. So I edited /etc/mysql/my.cnf
                  I added:



                  [client]
                  default-character-set = utf8mb4

                  [mysql]
                  default-character-set = utf8mb4

                  [mysqld]
                  character-set-server = utf8mb4
                  collation-server = utf8mb4_unicode_ci



                5. Restarting mysql (sudo service mysql restart) and running the same commands as above now gave me



                  +--------------------------+----------------------------+
                  | Variable_name | Value |
                  +--------------------------+----------------------------+
                  | character_set_client | utf8mb4 |
                  | character_set_connection | utf8mb4 |
                  | character_set_database | utf8mb4 |
                  | character_set_filesystem | binary |
                  | character_set_results | utf8mb4 |
                  | character_set_server | utf8mb4 |
                  | character_set_system | utf8 |
                  | character_sets_dir | /usr/share/mysql/charsets/ |
                  +--------------------------+----------------------------+


                  and



                  +----------------------+--------------------+
                  | Variable_name | Value |
                  +----------------------+--------------------+
                  | collation_connection | utf8mb4_general_ci |
                  | collation_database | utf8mb4_unicode_ci |
                  | collation_server | utf8mb4_unicode_ci |
                  +----------------------+--------------------+


                6. So I looked up the table settings using
                  SHOW TABLE STATUS FROM databasename;
                  They still used stuff like latin1_swedish_ci



                7. I used following to change the database setting:
                  ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
                  and following for each table:



                  use databasename;
                  ALTER TABLE assessments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;



                  1. Looking up again the table settings showed that latin1_swedish_ci was now changed to utf8mb4_unicode_ci

                  2. Then I changed the sqlalchemy connection url to use ?encoding=utf8mb4 at the end.

                  3. Restarted mysql again and the webapp. Since then it's working properly.









                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 23:11









                WTRipper

                304




                304






























                    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%2f53401602%2fincorrect-string-value-in-mysql-db%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

                    Tonle Sap (See)

                    I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                    Guatemaltekische Davis-Cup-Mannschaft