mysql 插入的数据是乱码
黄舟
黄舟 2017-04-17 13:28:37
0
4
444
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
大家讲道理

This is caused by the inconsistency between the encoding of the client and the encoding of the database.
Are you typing from the terminal?
For example, the encoding in your terminal is GBK, and although the server database uses UTF-8 encoding, it can recognize the GBK encoding data notified to the server and automatically convert it to UTF-8 for storage. You can use the following statement to quickly set the encoding set related to the client:
set names gbk;
After the setting is completed, the garbled problem of inserting data or displaying data on the client can be solved, but we will soon discover this The formal setting will only be effective in the current window. When the CMD client is reopened after the window is closed, garbled characters will appear. So, how to make a once-and-for-all setting? There is a my.conf configuration file in the MySQL installation directory. By modifying this configuration file, you can solve the garbled problem once and for all. In this configuration file [mysql] is related to the client configuration, and [mysqld] is related to the server configuration. The default configuration is as follows:

[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8

At this time, you only need to change the default encoding default-character-set=utf8 to default-character-set=gbk and restart the MySQL service.

黄舟

Before importing set names utf8;

小葫芦

This is usually a problem of inconsistent character set settings. Try setting it through the editor or setting it in the code

小葫芦

When I first learned to write programs, various garbled characters appeared. When the database was imported, garbled characters appeared. After the database was no longer garbled, the data read from the database displayed garbled characters and various garbled characters. Later, they were all unified to utf8.
The database was set to utf8. ,
When importing the file, the text type of the file is also utf8.
When importing through code, the charset is also set to utf8.
The file format edited by the editor is utf8.
The charset of the web page is also utf8.

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!