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

Summary of common tool examples in MySQL (recommended)

Preface This article mainly introduces the releva...

About the pitfalls of implementing specified encoding in MySQL

Written in front Environment: MySQL 5.7+, MySQL d...

DHCP Configuration Tutorial in CentOS7 Environment

Table of contents Configuration command steps in ...

MySQL 8.0.22 winx64 installation and configuration method graphic tutorial

The database installation tutorial of MySQL-8.0.2...

The difference between z-index: 0 and z-index: auto in CSS

I've been learning about stacking contexts re...

Using js to achieve the effect of carousel

Today, let's talk about how to use js to achi...

Tomcat configuration and how to start it in Eclipse

Table of contents How to install and configure To...

Example sharing of anchor tag usage in HTML

Anchor tag usage: Linking to a specific location i...

Mysql varchar type sum example operation

Some friends, when learning about databases, acci...

Linux kernel device driver system call notes

/**************************** * System call******...

JavaScript implementation of drop-down list

This article example shares the specific code of ...

Solution to many line breaks and carriage returns in MySQL data

Table of contents Find the problem 1. How to remo...

Div picture marquee seamless connection implementation code

Copy code The code is as follows: <html> &l...

Advertising skills in the Baidu Union environment (graphic tutorial)

Recently, students from the User Experience Team o...