08.10.2024 Have you read it yet 6364 once It helped 1 to the reader

The encoding of the "SITE_ID" field of the "b_abtest" table (utf8) differs from the encoding of the database (utf8mb3)

When testing the system check in the "Encoding tables in the database", the following error appeared:
Mistake! The table encodings have errors, the total number of errors is 2725, of which 0 can be automatically corrected.

We look at the details in the system check log and see the following messages:

The encoding of the "SITE_ID" field of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb3) The encoding of the "ACTIVE" field of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb3) The encoding of the "ENABLED" field of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb3) The encoding of the "NAME" of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb3) Encoding of the "DESCR" field of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb3) Encoding of the "TEST_DATA" field of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb3) Encoding of the "MODULE_ID" field of the table "b_admin_notify" (utf8) differs from the base encoding (utf8mb3) The encoding of the "TAG" field of the "b_admin_notify" table (utf8) differs from the base encoding (utf8mb3).....
This error occurs because the MySQL database uses different encodings between tables and fields. In our case, the encoding of the fields is utf8, whereas the encoding of the database is utf8mb3.

What's the difference?

The difference between utf8mb3 and utf8mb4 In MySQL, it's about the supported symbols and the way data is stored:

  1. Character support:

    • utf8mb3: This encoding supports characters that take up to three bytes. This means that it can store most of the characters used in modern languages, but it cannot handle some characters such as emojis and certain characters from languages that require four bytes.
    • utf8mb4 This encoding supports all Unicode characters, including those that take up four bytes, such as emojis and rare hieroglyphs.
  2. Storage length:

    • utf8mb3: The maximum string length is 3 bytes per character, which makes the maximum string length 767 bytes for indexes (in versions prior to MySQL 5.7).
    • utf8mb4 The maximum string length is 4 bytes per character, which allows for longer strings to be stored and provides more flexibility for storing different characters.
  3. Recommendations for use:

    • It is recommended to use utf8mb4 Instead of utf8mb3 for new projects, to ensure full support for all Unicode characters and avoid potential compatibility issues in the future.

This way, if the project requires support for emojis or other special characters., utf8mb4 — the best choice.

The response of 1C-Bitrix Technical Support to this issue

The situation is related to the fact that the check now does not take into account the encoding "utf8mb4"/"utf8mb3" as an exception and issues a remark as a result of the test. The development department has a request for this situation. The deadline for the decision depends entirely on the plans and workload of the development department. But as soon as there is news, we will notify you immediately.

As a solution, you can contact your server administrator to change the encoding of the corresponding tables in utf8 from the DBMS side. I would like to note that in this case, it is necessary to have an up-to-date backup copy of the system and an up-to-date valid backup of the server in order to restore it if necessary. After that, you can run configuration testing again and check if the specified situation has changed.

This encoding issue does not affect the operation of the site.

We will not wait for updates, we will proceed to changing the encoding of the table.:

  1. Creating a backup copy of the database so that we can return to its original state at any time. Next, we will carry out all actions on the work base.
  2. Changing the database encoding: In order to change the encoding, we will use the command ALTER TABLE.
    Execution steps in phpMyAdmin: Open your database in phpMyAdmin, go to the SQL tab, and paste the query ALTER DATABASE `your_name` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    Click Run to check the changes
    
  3. Changing the connection parameters in /bitrix/php_interface:.
    in after_connect.php:
    instead of: $DB->Query("SET NAMES 'utf8'"); $DB->Query('SET collation_connection = "utf8_unicode_ci"');
    
    specify: $DB->Query("SET NAMES 'utf8mb4'"); $DB->Query('SET collation_connection = "utf8mb4_general_ci"');

    in after_connect_d7.php:
    instead of: $this->queryExecute("SET NAMES 'utf8'"); $this->queryExecute('SET collation_connection = "utf8_unicode_ci"');
    
    specify: $this->queryExecute("SET NAMES 'utf8mb4'"); $this->queryExecute('SET collation_connection = "utf8mb4_general_ci"');
  4. Go back to Settings - Tools - System Check and start testing
    The following error may appear in the "Encoding tables in the database":
    Mistake! The table encodings have errors, the total number of errors is 2725, of which 0 can be automatically corrected.

    We look at the details in the system check log and see the following messages:

    The encoding of the "b_abtest" table (utf8mb3) differs from the encoding of the base (utf8mb4). The encoding of the "SITE_ID" field of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb4). The encoding of the "ACTIVE" field of the "b_abtest" table (utf8mb4) differs from the encoding of the "ENABLED" field of the "b_abtest" (utf8) differs from the encoding of the base (utf8mb4) Encoding of the "NAME" field of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb4) Encoding of the "DESCR" field of the "b_abtest" table (utf8) differs from the encoding of the base (utf8mb4) Encoding of the "TEST_DATA" field of the "b_abtest" table (utf8) differs from the base encoding (utf8mb4) .....
    
  5. We repeat the steps in step # 2, only changing the requests themselves. Now we need tables (not fields) to have encoding utf8mb3 change it to utf8mb4.
    Request example: ALTER TABLE `b_abtest` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    
  6. Back to the Settings - Tools - System Check and we start testing. We check that there are no errors in the "Encoding tables in the database", but they may appear in the next block "Database Structure".
    Mistake! The database structure has errors. There are 314 in total, which can be fixed automatically: 0.

    We look at the details in the system check log and see the following messages:

    In the b_event_type table, the DESCRIPTION field "`DESCRIPTION` mediumtext NULL DEFAULT NULL" does not match the description on disk "`DESCRIPTION` text NULL DEFAULT NULL" In the b_event_message table, the BCC field "`BCC` mediumtext NULL DEFAULT NULL" does not match the description on disk "`BCC` text NULL DEFAULT NULL" In the b_event_message table, the ADDITIONAL_FIELD "`ADDITIONAL_FIELD` mediumtext NULL DEFAULT NULL" does not match the description on disk "`ADDITIONAL_FIELD` text NULL DEFAULT NULL" In the b_group table, the SECURITY_POLICY field "`SECURITY_POLICY` mediumtext NULL DEFAULT NULL" does not match the description on disk "`SECURITY_POLICY` text NULL DEFAULT NULL" In the b_user table, the PERSONAL_STREET field "`PERSONAL_STREET`mediumtext NULL DEFAULT NULL" does not match the description on disk "`PERSONAL_STREET` text NULL DEFAULT NULL" In the b_user table, the PERSONAL_NOTES field "`PERSONAL_NOTES` mediumtext NULL DEFAULT NULL" does not match the description on disk "`PERSONAL_NOTES` text NULL DEFAULT NULL" .....
    
  7. We repeat the steps in step 2 again, but we only change the queries. Now we need to change the information about the description of the fields.
    Request example: ALTER TABLE `b_event_type` CHANGE `DESCRIPTION` `DESCRIPTION` text NULL DEFAULT NULL;
    
  8. Back to the Settings - Tools - System Check and we start testing. We check that there are no errors when Database testing
  9. The last step. We are launching database Optimization using Bitrix tools.
    Go to Settings - Tools - Diagnostics - Database Optimization, click Run and wait for the result.
    
  10. This concludes the procedure for changing the encoding of the c database. utf8mb3 on utf8mb4 completed.
Feedback

Was the material useful?

The assessment helps to understand which materials are worth developing and supplementing.

Discuss the task

Ask for help

Describe the task and leave your contacts. I will look at the introductory notes and contact you in a convenient way.

Direction *