Home > Database > Mysql Tutorial > body text

Solution to Chinese garbled characters in form input data in MySql_MySQL

WBOY
Release: 2016-09-09 08:13:44
Original
1010 people have browsed it

The reason why MySQL has Chinese garbled characters is because

1. Server itself setting problem, generally latin1

2. There is no encoding format specified when building the database and table.

Solution to Chinese garbled Chinese characters in form input data in MySql:

1. When building the database

CREATE DATABASE test 
CHARACTER SET 'utf8' 
COLLATE 'utf8_general_ci'; 
Copy after login

2. When creating a table

CREATE TABLE content ( 
text VARCHAR(100)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
Copy after login

Basically there will be no problems, that is, the same encoding format will be used when building databases and tables.

1. View the default encoding format:

show variables like "%char%"; 
Copy after login

The following is the modified version

mysql> show variables like "%char%"; 
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.13-osx10.11-x86_64/share/charsets/ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.01 sec) 
Copy after login

2. Check the encoding format of the test database:

The above is the solution to the problem of Chinese garbled characters in form input data in MySql introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support of the website!

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