今天我们要向大家介绍的是MySQL字符集设定全部参数为UTF8的实际操作步骤,本文主要是以MySQL字符集设定全部参数为UTF8的实际应用代码来引出其实际操作的具体操作,以下就是正文的主要内容。
MySQL字符集设定所有参数为UTF8:在安装完成以后已经设置MySQL(和PHP搭配之最佳组合)设置为utf8
但是如以下所示:
- MySQL(和PHP搭配之最佳组合)> SHOW VARIABLES LIKE 'collation_%';
- +----------------------+-------------------+
- | Variable_name | Value |
- +----------------------+-------------------+
- | collation_connection | latin1_swedish_ci |
- | collation_database | utf8_general_ci |
- | collation_server | utf8_general_ci |
- +----------------------+-------------------+
- 3 rows in set (0.00 sec)
- MySQL(和PHP搭配之最佳组合)> SHOW VARIABLES LIKE 'character_set_%';
- +--------------------------+------------------------------------------------+
- | Variable_name | Value |
- +--------------------------+------------------------------------------------+
- | character_set_client | latin1 |
- | character_set_connection | latin1 |
- | character_set_database | utf8 |
- | character_set_results | latin1 |
- | character_set_server | utf8 |
- | character_set_system | utf8 |
- | character_sets_dir | D:\data\MySQL(和PHP搭配之最佳组合)\MySQL(和PHP搭配之最佳组合) Server 4.1\share\charsets/ |
- +--------------------------+------------------------------------------------+
- 7 rows in set (0.00 sec)
发觉画线标注的属性还是非 utf8的。
然后修改 my.ini 文件,设置
以下是MySQL字符集设定所有参数为UTF8代码片段:
- [client]
- default-character-set=utf8
- [MySQL(和PHP搭配之最佳组合)]
- default-character-set=utf8
- [MySQL(和PHP搭配之最佳组合)d]
- default-character-set=utf8
copy my.ini 文件到 windows目录
启动MySQL(和PHP搭配之最佳组合) 以下是代码片段:
- MySQL(和PHP搭配之最佳组合)> SHOW VARIABLES LIKE ’character_set_%’;
- +--------------------------+------------------------------------------------+
- | Variable_name | Value |
- +--------------------------+------------------------------------------------+
- | character_set_client | utf8 |
- | character_set_connection | utf8 |
- | character_set_database | utf8 |
- | character_set_results | utf8 |
- | character_set_server | utf8 |
- | character_set_system | utf8 |
- | character_sets_dir | D:\data\MySQL(和PHP搭配之最佳组合)\MySQL(和PHP搭配之最佳组合) Server 4.1\share\charsets/ |
- +--------------------------+------------------------------------------------+
- 7 rows in set (0.00 sec)
- MySQL(和PHP搭配之最佳组合)> SHOW VARIABLES LIKE ’character_set_%’;
- +--------------------------+------------------------------------------------+
- | Variable_name | Value |
- +--------------------------+------------------------------------------------+
- | character_set_client | utf8 |
- | character_set_connection | utf8 |
- | character_set_database | utf8 |
- | character_set_results | utf8 |
- | character_set_server | utf8 |
- | character_set_system | utf8 |
- | character_sets_dir | D:\data\MySQL(和PHP搭配之最佳组合)\MySQL(和PHP搭配之最佳组合) Server 4.1\share\charsets/ |
- +--------------------------+------------------------------------------------+
- 7 rows in set (0.00 sec)
一切正常了。
创建数据库:
以下是代码片段:
- create table t_sysuser (
- USERID integer not null auto_increment,
- USERNAME varchar(30),
- PASSWORDS varchar(30),
- DEPTNO varchar(30),
- HEADSHIP varchar(30),
- SEX varchar(4),
- TEL varchar(18),
- EMAIL varchar(30),
- URL varchar(30),
- PCALL varchar(20),
- USERPHOTO varchar(255),
- FACEREFUTIME integer,
- FACELANGUAGE varchar(1),
- LASTMODIF varchar(30),
- LASTMDATE datetime,
- CREADTOR varchar(30),
- CREATDATE datetime,
- Prima(最完善的虚拟主机管理系统)ry key (USERID)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
全部搞定。
以上的相关内容就是对MySQL字符集设定所有参数为UTF8的介绍,望你能有所收获。
【编辑推荐】
- MySQL查询高速缓冲have_query_cache不得不看
- MySQL编码问题的经验总结
- Oracle数据库移植MySQL的事项有哪些 ?
- MySQL 服务器进行调优的“窍门”
- MySQL数据库初学者必读