Home > Database > Mysql Tutorial > body text

mysql 乱码的解决办法_MySQL

WBOY
Release: 2016-05-31 08:48:56
Original
864 people have browsed it

显示字符集,并将相应字符集更改为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 |

例如

SET character_set_client='utf8';
SET character_set_connection='utf8';
SET character_set_results='utf8'

创建表时:

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;

如果使用python的mysql连接,还需要在连接时设置charset,例如:

self.conn=MySQLdb.connect(host="127.0.0.1",user="root", passwd="000", db="app_db",port=3306,charset='utf8')

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