在MySQL中使用utf8mb4 [英] Using utf8mb4 in MySQL

查看:196
本文介绍了在MySQL中使用utf8mb4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在MySQL(5.6.11)中使用4字节utf8mb4,我在my.ini文件中设置了以下变量(未找到my.cnf).该文件位于Windows XP上名为Application Data(C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6)的隐藏文件夹中.在安装目录下不可用.

In order to use 4-byte utf8mb4 in MySQL (5.6.11), I have set the following variables in the my.ini file (my.cnf is not found). This file is located in a hidden folder named Application Data (C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6) on Windows XP. It is not available under the installation directory.

[client]
port=3306
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

[mysqld]
init-connect='SET NAMES utf8mb4'
collation_server=utf8mb4_unicode_ci
character_set_server=utf8mb4

然后发出以下命令,

SHOW VARIABLES
WHERE Variable_name
LIKE 'character\_set\_%'
OR Variable_name LIKE 'collation%';

仍显示以下列表.

从图片本身可以明显看出,几个变量仍在使用3字节的utf8.

From the picture itself, it is clear that several variables are still using 3-byte utf8.

在执行此操作之前,已经发出以下命令来对数据库本身进行相应的更改.

Before doing this, the following command had already been issued to make corresponding changes to the database itself.

ALTER DATABASE database_name
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

在上述数据库中的每个表上也都发出了以下命令.

And the following command had also been issued on each and every table in the said database.

ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;


但是,为什么尚未对所述字符集和排序规则设置一些变量的原因是什么?缺少什么?


Nevertheless, what is the reason why some variables have not yet been set to the said character set as well as the collation? What is missing?

在执行了上面指定的每个任务之后,系统(操作系统)本身已重新启动.

The system (operating system) itself was restarted after every single task specified above had been carried out.

推荐答案

client 通常在连接时设置这些值. my.ini中的设置仅是默认设置,当客户端未显式指定连接编码时将应用这些设置.由于它们不可靠,因此每个客户端都应指定连接编码.由于您有一些漂亮的屏幕截图,所以我猜您正在连接一些GUI实用程序,该实用程序可能明确地确实设置了一些连接编码.

The client usually sets these values when connecting. The settings in my.ini are merely defaults which apply when the client does not explicitly specify a connection encoding. Since they're unreliable, every client should specify a connection encoding. Since you've got some fancy screenshot there I'll guess that you're connecting with some GUI utility which probably explicitly does set some connection encodings.

设置连接字符集的PHP示例:

PHP example of setting a connection charset:

new PDO('mysql:host=localhost;charset=utf8mb4')

这篇关于在MySQL中使用utf8mb4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆