Home > Database > Mysql Tutorial > MySQL字符集的实际操作流程示例

MySQL字符集的实际操作流程示例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:14:15
Original
1418 people have browsed it

以下的文章主要介绍的是MySQL字符集的实际应用,其中包括如何正确配置MySQL数据库的默认字符集,以及查看数据库当前所使用MySQL数据库字符集有哪些?以下就是文章的主要内容描述, 1. 配置MySQL默认字符集 [client] default-character-set = utf8 客户端连接

以下的文章主要介绍的是MySQL字符集的实际应用,其中包括如何正确配置MySQL数据库的默认字符集,以及查看数据库当前所使用MySQL数据库字符集有哪些?以下就是文章的主要内容描述,

1. 配置MySQL默认字符集

<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>
</ol>
Copy after login

客户端连接默认MySQL字符集

<ol class="dp-xml">
<li class="alt"><span>[MySQLd]  </span></li>
<li>
<span class="attribute">default-character-set</span><span>=</span><span class="attribute-value">utf8</span><span>  </span>
</li>
</ol>
Copy after login

MySQLd默认字符集

2. 查看MySQL当前使用MySQL字符集

<ol class="dp-xml">
<li class="alt">MySQL<span><span class="tag">></span><span> show variables like 'character%';  </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_filesystem | binary |  </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 | /usr/local/</span>MySQL<span>/share/</span>MySQL<span>/charsets/ |  </span>
</li>
<li class="alt"><span>+--------------------------+----------------------------------------+ </span></li>
</ol>
Copy after login

使用MySQL命令修改MySQL字符集

<ol class="dp-xml">
<li class="alt">MySQL<span><span class="tag">></span><span> SET </span><span class="attribute">character_set_client</span><span> = </span><span class="attribute-value">utf8</span><span> ;  </span></span>
</li>
<li>MySQL<span class="tag">></span><span> SET </span><span class="attribute">character_set_connection</span><span> = </span><span class="attribute-value">utf8</span><span> ;  </span>
</li>
<li class="alt">MySQL<span class="tag">></span><span> SET </span><span class="attribute">character_set_database</span><span> = </span><span class="attribute-value">utf8</span><span> ;  </span>
</li>
<li>MySQL<span class="tag">></span><span> SET </span><span class="attribute">character_set_results</span><span> = </span><span class="attribute-value">utf8</span><span> ;  </span>
</li>
<li class="alt">MySQL<span class="tag">></span><span> SET </span><span class="attribute">character_set_server</span><span> = </span><span class="attribute-value">utf8</span><span> ; </span>
</li>
</ol>
Copy after login

3. C api

<ol class="dp-xml">
<li class="alt">MySQL<span>_options(</span>MySQL<span>, </span>MySQL<span>_SET_CHARSET_NAME, 'utf8');  </span>
</li>
<li>MySQL<span>_real_connect(</span>MySQL<span>, ...); </span>
</li>
</ol>
Copy after login

大部分情况下,使用MySQL默认编码latin1可以解决MySQL乱码问题。同时在插入数据和读取数据时,不需要通过MySQL_options来指定编码类型。配置文件my.cnf也不需要指定编码类型。


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template