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

JavaScript regular verification password strength implementation method

exhibit design Password strength analysis The pas...

The viewport in the meta tag controls the device screen css

Copy code The code is as follows: <meta name=&...

Solution to inserting a form with a blank line above and below

I don't know if you have noticed when making a...

How to build a React project with Vite

Table of contents Preface Create a Vite project R...

How to use crontab to backup MySQL database regularly in Linux system

Use the system crontab to execute backup files re...

Summary of special processing statements of MySQL SQL statements (must read)

1. Update the entire table. If the value of a col...

JavaScript css3 to implement simple video barrage function

This article attempts to write a demo to simulate...

JavaScript to implement image preloading and lazy loading

This article shares the specific code for impleme...

Vue realizes simple effect of running light

This article shares the specific code of Vue to a...

Promise encapsulation wx.request method

The previous article introduced the implementatio...

Summary of Docker common commands and tips

Installation Script Ubuntu / CentOS There seems t...

JavaScript to achieve magnifying glass effect

This article shares the specific code for JavaScr...

JavaScript to achieve the effect of tab bar switching

Tab bar: Click different tabs to display differen...

Vue+Bootstrap realizes a simple student management system

I used vue and bootstrap to make a relatively sim...