Home > Database > Mysql Tutorial > body text

What should I do if the Chinese in mysql cannot be displayed?

coldplay.xixi
Release: 2020-10-19 11:52:44
Original
6916 people have browsed it

Solution to the problem that Chinese characters in mysql cannot be displayed: 1. Find the mysql configuration file [my.ini], find [default-character-set], and change the parameters to gbk; 2. Check the structure of the table , change the character set of username in the user table.

What should I do if the Chinese in mysql cannot be displayed?

##More related free learning recommendations: mysql tutorial(Video)

Solution to the problem that Chinese cannot be displayed in mysql:

1. Because the windows operating system uses gb2312 by default This character, when mysql is installed, both the client and the server use latin1 by default, so this leads to a problem of character set and character verification mismatch. At this time, you only need to find the mysql configuration file

my.iniFind default-character-set and just change its parameters to gbk. There are two such parameters, one for the client and one for the server.

2. For the previous database, the path was specified by the datadir in my.ini. There are many folders under the data folder, namely the database. There is a db.opt file below, the content of which is

default-character- set=latin1 default-collation=latin1_swedish_ci Change to default-character-set=gbk defaultcollation=gbk_chinese_ci and restart the service. The encoding method of tables created later will change. Can display Chinese.

3. Chinese cannot be inserted due to the field encoding of the table. Solution:

View the structure of the table:

mysql> show create table users;
Copy after login

Change the character set of username in the users table. Because there is already data in the table, the operation of changing the username character set must first clear the data in the users table

mysql> truncate table users;
Copy after login

Change the character set of username in the user table

mysql> alter table users modify username char(20) character set gbk;
Copy after login

Then insert Chinese characters , the insertion is successful.

mysql> insert into users values(88,'中文');
Copy after login

4. An error occurred in mysql Can't create table "table name" (errno: 121)

The data file still exists, so if you create a data file with the same name, an error will occur. The solution is: delete the current database first, and then re-create the database and tables. You should delete it first and then create the database drop database xxxxcreate database xxxx

The above is the detailed content of What should I do if the Chinese in mysql cannot be displayed?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!