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

Mini Program to Implement Text Circular Scrolling Animation

This article shares the specific code of the appl...

How to introduce Excel table plug-in into Vue

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

PHP related paths and modification methods in Ubuntu environment

PHP related paths in Ubuntu environment PHP path ...

MySQL trigger usage scenarios and method examples

trigger: Trigger usage scenarios and correspondin...

How to run Spring Boot application in Docker

In the past few days, I have studied how to run s...

React Hook usage examples (6 common hooks)

1. useState: Let functional components have state...

Detailed example of jQuery's chain programming style

The implementation principle of chain programming...

How to Install Xrdp Server (Remote Desktop) on Ubuntu 20.04

Xrdp is an open source implementation of Microsof...

Recommend a cool flashing alarm button

The effect is as follows: The code is as follows ...

jQuery implements simple pop-up window effect

This article shares the specific code of jQuery t...

CentOS7 64-bit installation mysql graphic tutorial

Prerequisites for installing MySQL: Install CentO...

Echarts implements switching different X-axes in one graph (example code)

Rendering If you want to achieve the effect shown...

Detailed explanation of JavaScript function introduction

Table of contents Function Introduction function ...