1、用 SET 语法来指定,不加 "GLOBAL" 的话就只对本次会话有效。
SET [GLOBAL] character_set_client = utf8; SET [GLOBAL] character_set_connection = utf8; SET [GLOBAL] character_set_database = utf8; SET [GLOBAL] character_set_results = utf8; SET [GLOBAL] character_set_server = utf8;
2、只对本次会话有效。
SET NAMES 'utf8';
3、直接修改 my.cnf,[client]和[MySQLd]下面各增加一行内容,然后重启 MySQL,全局生效。
default-character-set = utf8