Some problems that may be caused by inconsistent MySQL encoding

Some problems that may be caused by inconsistent MySQL encoding

Stored procedures and coding

In MySQL stored procedures, if the encoding of the table and data is different from the default encoding of the database and stored procedures, SQL may not use the index, because MySQL will perform corresponding encoding conversion on the data in the condition column. For example, in the following, the table data is latin1, and the MySQL parser will do some conversion:

... WHERE namecolumn = NAME_CONST('in_namecolumn',_utf8'MP201022' COLLATE 'utf8_general_ci')

You can do the corresponding encoding conversion in the stored procedure (usually modify the varchar/char field) so that the index can be used normally. For more information, see: mysql-slow-when-run-as-stored-proc

... WHERE namecolumn = convert(in_namecolumn using latin1) collate latin1_swedish_ci

JDBC direct connection to execute SQL

When executing SQL through jdbc connection, if the encoding is inconsistent, the varchar and char types also need to be converted, as shown below:

... WHERE namecolumn = convert(in_namecolumn using latin1) collate latin1_swedish_ci

Otherwise, the following encoding inconsistency errors may occur (depending on the mysql-connector version, the behavior may vary):

SQL state [HY000]: error code [1267]: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='

jdbc useSSL parameter changes

In the mysql-connector-java configuration, the useSSL parameter has the following differences. Starting from 5.1.38, useSSL is enabled by default for MySQL 5.5.45+, 5.6.26+ or 5.7.6+. The corresponding requireSSL and verifyServerCertificate parameters will also be enabled:

< 5.1.38:
 ConnectionProperties.useSSL=Use SSL when communicating with the server (true/false), defaults to 'false'

>= 5.1.38
 ConnectionProperties.useSSL=Use SSL when communicating with the server (true/false), default is 'true' when connecting to MySQL 5.5.45+, 5.6.26+ or 5.7.6+, otherwise default is 'false'

MySQL 5.7.x and above will enable SSL by default, and the client will automatically negotiate encryption when connecting, unless explicitly specified not to encrypt. mysql-connector-java has enabled useSSL by default since 5.1.38. So there will be no encryption problems when connecting to MySQL 5.7.x with a lower version of jdbc, but there will be encryption problems when connecting to 5.7.6+ with a higher version of jdbc. You need to explicitly specify useSSL=false, and there will be no encryption problems when connecting to MySQL 5.5, 5.6 with a higher version of jdbc.

This is the end of this article about some problems that may be caused by inconsistent MySQL encoding. For more information about problems caused by inconsistent MySQL encoding, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Several solutions to the garbled Chinese encoding of uft-8 in php and mysql
  • How to view and modify the current database encoding in MySQL
  • How to modify the encoding method of tables and fields in MySQL database
  • MySql changes the database encoding to UTF8 to avoid garbled characters
  • How to view and modify character encoding in MySQL
  • Solution to garbled characters when using UTF-8 Chinese encoding in MYSQL database
  • Mysql database encoding problem (modify database, table, field encoding to utf8)
  • Modify the default encoding of MySQL 5.5 (change the graphic steps to utf-8 encoding)
  • Check and modify the mysql encoding to support Chinese (gbk or utf8)
  • MySQL character encoding setting method

<<:  Several situations where div is covered by iframe and their solutions

>>:  Implementation of nginx virtual host settings based on domain name, port, and different IP

Recommend

Docker-compose installation yml file configuration method

Table of contents 1. Offline installation 2. Onli...

Introduction to the usage of props in Vue

Preface: In Vue, props can be used to connect ori...

Web2.0: Causes and Solutions of Information Overload

<br />Information duplication, information o...

Windows 2019 Activation Tutorial (Office2019)

A few days ago, I found that the official version...

React Fragment Introduction and Detailed Usage

Table of contents Preface Motivation for Fragment...

Detailed explanation of using JavaScript WeakMap

A WeakMap object is a collection of key/value pai...

Four categories of CSS selectors: basic, combination, attribute, pseudo-class

What is a selector? The role of the selector is t...

Vue+element ui realizes anchor positioning

This article example shares the specific code of ...

Basic usage of UNION and UNION ALL in MySQL

In the database, both UNION and UNION ALL keyword...

Learning to build React scaffolding

1. Complexity of front-end engineering If we are ...

Several methods to clear floating (recommended)

1. Add an empty element of the same type, and the...

Solution to Nginx SSL certificate configuration error

1. Introduction When a web project is published o...

Vue implements simple notepad function

This article example shares the specific code of ...

Two ways to reset the root password of MySQL database using lnmp

The first method: Use Junge's one-click scrip...

How to add Nginx proxy configuration to allow only internal IP access

location / { index index.jsp; proxy_next_upstream...