Encoding problems and solutions when mysql associates two tables

Encoding problems and solutions when mysql associates two tables

When Mysql associates two tables, an error message is generated: Illegal mix of collations

1. First use the tool to change the encoding method of the database and two tables

2. This step is very important and requires changing the encoding method of the field.

ALTER TABLE `table name` CHANGE `dev_chancode` `field` VARCHAR(32) CHARACTER SET gbk NOT NULL;

Summary: When creating a table, you must pay attention to the unified encoding method, otherwise it will be very troublesome to deal with it later.

How to solve the MySQL table encoding conversion problem

  1. Export the table structure of the data table to be exported (you can use Phpmyadmin, mysqldump, etc., it's very simple and I won't explain it in detail), then change the CHARSET=latin1 of the exported create table statement to CHARSET=utf8, execute the create table statement in the target library newdbname to build the table structure, and then start exporting and importing data. Order:
  2. ./mysqldump -d DB_Dig > /usr/local/tmp/tables.sql
  3. Command line: Enter the mysql command line, mysql -hlocalhost -uroot -p*** dbname
  4. Execute SQL select * from tbname into outfile '/usr/local/tbname.sql';
  5. Convert tbname.sql to UTF-8 format. It is recommended to use UltraEditor. You can directly use the editor's 'Convert->ASCII to UTF-8 (Unicode Editing)', or save the file as UTF-8 (without BOM) format.
  6. Execute the statement set character_set_database=utf8 in the mysql command line; Note: Set the mysql environment variable so that mysql will interpret the content of the sql file in utf8 format when reading the sql file in the next step
  7. Execute the statement load data infile 'tbname.sql' into table newdbname.tbname in the mysql command line;

The above is all the knowledge points introduced this time. Thank you for your learning and support for 123WORDPRESS.COM.

You may also be interested in:
  • Solutions to encoding problems encountered when comparing dates in MySQL
  • Mysql database encoding problem (modify database, table, field encoding to utf8)
  • Solving the Mysql5 character set encoding problem

<<:  Install JDK8 in rpm mode on CentOS7

>>:  Summary of three rules for React state management

Recommend

Vue+swiper realizes timeline effect

This article shares the specific code of vue+swip...

Solve the Linux Tensorflow2.0 installation problem

conda update conda pip install tf-nightly-gpu-2.0...

Summary of knowledge points about covering index in MySQL

If an index contains (or covers) the values ​​of ...

MySQL 8.0.23 installation and configuration method graphic tutorial under win10

This article shares the installation and configur...

Example of Vue uploading files using formData format type

In Vue, we generally have front-end and back-end ...

Vue3.0 implements the magnifying glass effect case study

The effect to be achieved is: fixed zoom in twice...

How to introduce Excel table plug-in into Vue

This article shares the specific code of Vue intr...

How does Vue solve the cross-domain problem of axios request front end

Table of contents Preface 1. Why do cross-domain ...

SVG button example code based on CSS animation

The specific code is as follows: <a href="...

Detailed installation and use of docker-compose

Docker Compose is a Docker tool for defining and ...

Detailed explanation of nginx forward proxy and reverse proxy

Table of contents Forward Proxy nginx reverse pro...

Put frameset in body through iframe

Because frameset and body are on the same level, y...

Summary of commonly used commands for docker competition submission

Log in to your account export DOCKER_REGISTRY=reg...

Analysis of the use of Linux vulnerability scanning tool lynis

Preface: Lynis is a security audit and hardening ...

A brief discussion on several advantages of Vue3

Table of contents 1. Source code 1.1 Monorepo 1.2...