Coding Problem and Solution of mysql Correlating Two Tables

  • 2021-12-12 10:05:40
  • OfStack

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

1. First, use tools to change the coding mode of database and two tables

2. This step is very important, and it is necessary to change the encoding method of fields.


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

Summary: When building a table, we should pay attention to the coding mode of Unified 1, and it will be super troublesome to make it follow-up.

How to solve the coding conversion problem of MySQL table

Export the table structure of the data table to be exported (Phpmyadmin, mysqldump, etc. can be used, but it is simply not mentioned), then change 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-importing data. Command: ./mysqldump -d DB_Dig > /usr/local/tmp/tables.sql Command line: Enter the command line mysql, mysql-hlocalhost-uroot-p*** dbname Execute SQL select * from tbname into outfile '/usr/local/tbname. sql'; Transcode tbname. sql to utf-8 format. UltraEditor is recommended. You can use the editor's' Transform- > ASCII to UTF-8 (Unicode edit) ', or save the file in UTF-8 (no BOM) format Execute the statement set character_set_database=utf8 on the mysql command line; Note: Set the environment variable of mysql, so that mysql will interpret the contents of utf file in the form of utf8 when reading sql file in the next step Execute the statement load data infile 'tbname. sql' into table newdbname. tbname on the mysql command line;

The above is all the knowledge points introduced this time. Thank you for your study and support for this site.


Related articles: