MySQL 4.1 and above has a default character set of UTF-8. You can verify this in your my.cnf file, remember to set 都有 client and server (default-character-set and character-set-server).
如果您希望将现有数据转换为 UTF-8,请转储数据库,并将其导入回 UTF-8,以确保:
在查询/插入数据库之前使用 SET NAMES utf8
创建新表时使用 DEFAULT CHARSET=utf8
此时,您的 MySQL 客户机和服务器应该是 UTF-8(参见 my.cnf)。请记住您使用的任何语言(如 PHP)也必须是 UTF-8。PHP 的某些版本将使用它们自己的 MySQL 客户端库,这些库可能不支持 UTF-8。
字符集是数据库(默认)和表的属性。
You can have a look (MySQL commands):
show create database foo;
> CREATE DATABASE `foo`.`foo` /*!40100 DEFAULT CHARACTER SET latin1 */
show create table foo.bar;
> lots of stuff ending with
> ) ENGINE=InnoDB AUTO_INCREMENT=252 DEFAULT CHARSET=latin1
SET NAMES UTF8;
set collation_server = utf8_general_ci;
set default-character-set = utf8;
set init_connect = ’SET NAMES utf8′;
set character_set_server = utf8;
set character_set_client = utf8;
$connect = mysql_connect('$localhost','$username','$password') or die(mysql_error());
mysql_set_charset('utf8',$connect);
mysql_select_db('$database_name','$connect') or die(mysql_error());