Maison >base de données >tutoriel mysql >MySQL字符集设定全部参数为UTF8的代码示例
今天我们要向大家介绍的是MySQL字符集设定全部参数为UTF8的实际操作步骤,本文主要是以MySQL字符集设定全部参数为UTF8的实际应用代码来引出其实际操作的具体操作,以下就是正文的主要内容。 MySQL字符集设定所有参数为UTF8:在安装完成以后已经设置MySQL(和P
今天我们要向大家介绍的是MySQL字符集设定全部参数为UTF8的实际操作步骤,本文主要是以MySQL字符集设定全部参数为UTF8的实际应用代码来引出其实际操作的具体操作,以下就是正文的主要内容。
MySQL字符集设定所有参数为UTF8:在安装完成以后已经设置MySQL(和PHP搭配之最佳组合)设置为utf8
但是如以下所示:
<ol class="dp-xml"> <li class="alt"><span><span>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> SHOW VARIABLES LIKE 'collation_%'; </span></span></li> <li><span>+----------------------+-------------------+ </span></li> <li class="alt"><span>| Variable_name | Value | </span></li> <li><span>+----------------------+-------------------+ </span></li> <li class="alt"><span>| collation_connection | latin1_swedish_ci | </span></li> <li><span>| collation_database | utf8_general_ci | </span></li> <li class="alt"><span>| collation_server | utf8_general_ci | </span></li> <li><span>+----------------------+-------------------+ </span></li> <li class="alt"><span>3 rows in set (0.00 sec) </span></li> <li> <span>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> SHOW VARIABLES LIKE 'character_set_%'; </span> </li> <li class="alt"><span>+--------------------------+------------------------------------------------+ </span></li> <li><span>| Variable_name | Value | </span></li> <li class="alt"><span>+--------------------------+------------------------------------------------+ </span></li> <li><span>| character_set_client | latin1 | </span></li> <li class="alt"><span>| character_set_connection | latin1 | </span></li> <li><span>| character_set_database | utf8 | </span></li> <li class="alt"><span>| character_set_results | latin1 | </span></li> <li><span>| character_set_server | utf8 | </span></li> <li class="alt"><span>| character_set_system | utf8 | </span></li> <li><span>| character_sets_dir | D:\data\MySQL(和PHP搭配之最佳组合)\MySQL(和PHP搭配之最佳组合) Server 4.1\share\charsets/ | </span></li> <li class="alt"><span>+--------------------------+------------------------------------------------+ </span></li> <li><span>7 rows in set (0.00 sec) </span></li> </ol>
发觉画线标注的属性还是非 utf8的。
然后修改 my.ini 文件,设置
以下是MySQL字符集设定所有参数为UTF8代码片段:
<ol class="dp-xml"> <li class="alt"><span><span>[client] </span></span></li> <li> <span class="attribute">default-character-set</span><span>=</span><span class="attribute-value">utf8</span><span> </span> </li> <li class="alt"><span>[MySQL(和PHP搭配之最佳组合)] </span></li> <li> <span class="attribute">default-character-set</span><span>=</span><span class="attribute-value">utf8</span><span> </span> </li> <li class="alt"><span>[MySQL(和PHP搭配之最佳组合)d] </span></li> <li> <span class="attribute">default-character-set</span><span>=</span><span class="attribute-value">utf8</span><span> </span> </li> <li class="alt"><span> </span></li> </ol>
copy my.ini 文件到 windows目录
启动MySQL(和PHP搭配之最佳组合) 以下是代码片段:
<ol class="dp-xml"> <li class="alt"><span><span>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> SHOW VARIABLES LIKE ’character_set_%’; </span></span></li> <li><span>+--------------------------+------------------------------------------------+ </span></li> <li class="alt"><span>| Variable_name | Value | </span></li> <li><span>+--------------------------+------------------------------------------------+ </span></li> <li class="alt"><span>| character_set_client | utf8 | </span></li> <li><span>| character_set_connection | utf8 | </span></li> <li class="alt"><span>| character_set_database | utf8 | </span></li> <li><span>| character_set_results | utf8 | </span></li> <li class="alt"><span>| character_set_server | utf8 | </span></li> <li><span>| character_set_system | utf8 | </span></li> <li class="alt"><span>| character_sets_dir | D:\data\MySQL(和PHP搭配之最佳组合)\MySQL(和PHP搭配之最佳组合) Server 4.1\share\charsets/ | </span></li> <li><span>+--------------------------+------------------------------------------------+ </span></li> <li class="alt"><span>7 rows in set (0.00 sec) </span></li> <li> <span>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> SHOW VARIABLES LIKE ’character_set_%’; </span> </li> <li class="alt"><span>+--------------------------+------------------------------------------------+ </span></li> <li><span>| Variable_name | Value | </span></li> <li class="alt"><span>+--------------------------+------------------------------------------------+ </span></li> <li><span>| character_set_client | utf8 | </span></li> <li class="alt"><span>| character_set_connection | utf8 | </span></li> <li><span>| character_set_database | utf8 | </span></li> <li class="alt"><span>| character_set_results | utf8 | </span></li> <li><span>| character_set_server | utf8 | </span></li> <li class="alt"><span>| character_set_system | utf8 | </span></li> <li><span>| character_sets_dir | D:\data\MySQL(和PHP搭配之最佳组合)\MySQL(和PHP搭配之最佳组合) Server 4.1\share\charsets/ | </span></li> <li class="alt"><span>+--------------------------+------------------------------------------------+ </span></li> <li><span>7 rows in set (0.00 sec) </span></li> </ol>
一切正常了。
创建数据库:
以下是代码片段:
<ol class="dp-xml"> <li class="alt"><span><span>create table t_sysuser ( </span></span></li> <li><span>USERID integer not null auto_increment, </span></li> <li class="alt"><span>USERNAME varchar(30), </span></li> <li><span>PASSWORDS varchar(30), </span></li> <li class="alt"><span>DEPTNO varchar(30), </span></li> <li><span>HEADSHIP varchar(30), </span></li> <li class="alt"><span>SEX varchar(4), </span></li> <li><span>TEL varchar(18), </span></li> <li class="alt"><span>EMAIL varchar(30), </span></li> <li><span>URL varchar(30), </span></li> <li class="alt"><span>PCALL varchar(20), </span></li> <li><span>USERPHOTO varchar(255), </span></li> <li class="alt"><span>FACEREFUTIME integer, </span></li> <li><span>FACELANGUAGE varchar(1), </span></li> <li class="alt"><span>LASTMODIF varchar(30), </span></li> <li><span>LASTMDATE datetime, </span></li> <li class="alt"><span>CREADTOR varchar(30), </span></li> <li><span>CREATDATE datetime, </span></li> <li class="alt"><span>Prima(最完善的虚拟主机管理系统)ry key (USERID) </span></li> <li> <span>) </span><span class="attribute">ENGINE</span><span>=</span><span class="attribute-value">InnoDB</span><span> DEFAULT </span><span class="attribute">CHARSET</span><span>=</span><span class="attribute-value">utf8</span><span>; </span> </li> </ol>
全部搞定。
以上的相关内容就是对MySQL字符集设定所有参数为UTF8的介绍,望你能有所收获。