Home  >  Article  >  Database  >  What should I do if mysql cannot store Chinese strings?

What should I do if mysql cannot store Chinese strings?

藏色散人
藏色散人Original
2020-11-13 09:42:473533browse

The solution to the problem that mysql cannot store Chinese strings: first change the character set of the database and table to utf8; then delete the relevant fields and recreate them; finally use SQL statements to modify the character set to utf8.

What should I do if mysql cannot store Chinese strings?

Recommended: "mysql video tutorial"

I have been installing the MySQL-Cluster cluster service these days and found that the installation Afterwards, an error occurred when saving Chinese characters when operating the database. Navicat reported an error as shown in the figure:

The detection found that when MySQL did not set the default character set, the default character set was latin1, which did not Supporting Chinese characters, then our solution is very clear, which is to change the character set.

We first change the character set of the database

We then change the character set of the table:

At this point, I still get an error when saving the data. I checked the information again and found that the field also has a character set

show full columns from bd_user;

After deleting this field and re-creating it, the character set will be fine

Of course, we can also use SQL statements to modify the character set:

alter database test default character set = utf8; // test为数据库名
alter table test.bd_user default character set = utf8;  // bd_user为表名
alter table test.bd_user modify column user_name varchar(20) character set utf8 collate utf8_general_ci; // 这里也会改变字段类型

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

Statement:
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