Mysql garbled solution: display the character set and change the corresponding character set to utf8
Show variables like "% char % ";
+ -------------------------- + --------------- +
| Variable_name | Value |
+ -------------------------- + --------------- +
| Character_set_client | gbk |
| Character_set_connection | gbk |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | gbk |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
For example
SET character_set_client = 'utf8 ';
SET character_set_connection = 'utf8 ';
SET character_set_results = 'utf8'
When creating a table:
Create table video_author (
Sid bigint (11) not null AUTO_INCREMENT,
Nick varchar (64) not null,
Url 'varchar (128) not null,
Video_type set ('Dota ', 'Lol', 'hearthstone '),
Primary key (sid ),
KEY index_name (nick)
)ENGINE = InnoDB default charset = utf8;
If you are using a python mysql connection, you also need to set charset during the connection, for example:
Self. conn = MySQLdb. connect (host = "127.0.0.1", user = "root", passwd = "000", db = "app_db", port = 3306,Charset = 'utf8')