<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OurApache &#187; mysql</title>
	<atom:link href="http://ourapache.com/archives/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://ourapache.com</link>
	<description>我们致力于一个Apache知识的分享网站</description>
	<lastBuildDate>Tue, 13 Apr 2010 05:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>linux下查看nginx，apache，mysql，php的编译参数</title>
		<link>http://ourapache.com/archives/286</link>
		<comments>http://ourapache.com/archives/286#comments</comments>
		<pubDate>Thu, 13 Aug 2009 15:57:00 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[编译]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=286</guid>
		<description><![CDATA[有时候nginx，apache，mysql，php编译完了想看看编译参数可以用以下方法]]></description>
			<content:encoded><![CDATA[<p>有时候nginx，apache，<a href="http://ourapache.com/archives/tag/mysql" class="st_tag internal_tag" rel="tag" title="标签 mysql 下的日志">mysql</a>，php编译完了想看看编译参数可以用以下方法</p>
<p><strong>nginx编译参数：</strong></p>
<blockquote><p>#/usr/local/<a href="http://ourapache.com/archives/tag/nginx" class="st_tag internal_tag" rel="tag" title="标签 nginx 下的日志">nginx</a>/sbin/<a href="http://ourapache.com/archives/tag/nginx" class="st_tag internal_tag" rel="tag" title="标签 nginx 下的日志">nginx</a> -V<br />
nginx version: nginx/0.6.32</p>
<p>built by gcc 4.1.2 20071124 (Red Hat 4.1.2-42)</p>
<p>configure arguments: &#8211;user=www &#8211;group=www &#8211;prefix=/usr/local/nginx/ &#8211;with-http_stub_status_module &#8211;with-openssl=/usr/local/openssl</p></blockquote>
<p><strong>apache编译参数：</strong></p>
<blockquote><p># cat /usr/local/apache2/build/config.nice<br />
#! /bin/sh</p>
<p>#</p>
<p># Created by configure</p>
<p>“./configure” \</p>
<p>“&#8211;prefix=/usr/local/apache2&#8243; \</p>
<p>“&#8211;with-included-apr” \</p>
<p>“&#8211;enable-so” \</p>
<p>“&#8211;enable-deflate=shared” \</p>
<p>“&#8211;enable-expires=shared” \</p>
<p>“&#8211;enable-rewrite=shared” \</p>
<p>“&#8211;enable-static-support” \</p>
<p>“&#8211;disable-userdir” \</p>
<p>“$@”</p></blockquote>
<p><strong>php编译参数：</strong></p>
<blockquote><p># /usr/local/<a href="http://ourapache.com/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a>/bin/<a href="http://ourapache.com/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a> -i |grep configure</p>
<p>Configure Command =&gt; &#8216;./configure&#8217; &#8216;&#8211;prefix=/usr/local/php&#8217; &#8216;&#8211;with-apxs2=/usr/local/apache2/bin/apxs&#8217; &#8216;&#8211;with-config-file-path=/usr/local/php/etc&#8217; &#8216;&#8211;with-mysql=/usr/local/mysql&#8217; &#8216;&#8211;with-libxml-dir=/usr/local/libxml2/bin&#8217; &#8216;&#8211;with-gd=/usr/local/gd2&#8242; &#8216;&#8211;with-jpeg-dir&#8217; &#8216;&#8211;with-png-dir&#8217; &#8216;&#8211;with-bz2&#8242; &#8216;&#8211;with-xmlrpc&#8217; &#8216;&#8211;with-freetype-dir&#8217; &#8216;&#8211;with-zlib-dir&#8217;</p></blockquote>
<p><strong>mysql编译参数：</strong></p>
<blockquote><p># cat “/usr/local/mysql/bin/mysqlbug”|grep configure</p>
<p># This is set by configure</p>
<p>CONFIGURE_LINE=”./configure &#8216;&#8211;prefix=/usr/local/mysql&#8217; &#8216;&#8211;localstatedir=/var/lib/mysql&#8217; &#8216;&#8211;with-comment=Source&#8217; &#8216;&#8211;with-server-suffix=-H863&#8242; &#8216;&#8211;with-mysqld-user=mysql&#8217; &#8216;&#8211;without-debug&#8217; &#8216;&#8211;with-big-tables&#8217; &#8216;&#8211;with-charset=gbk&#8217; &#8216;&#8211;with-collation=gbk_chinese_ci&#8217; &#8216;&#8211;with-extra-charsets=all&#8217; &#8216;&#8211;with-pthread&#8217; &#8216;&#8211;enable-static&#8217; &#8216;&#8211;enable-thread-safe-client&#8217; &#8216;&#8211;with-client-ldflags=-all-static&#8217; &#8216;&#8211;with-mysqld-ldflags=-all-static&#8217; &#8216;&#8211;enable-assembler&#8217; &#8216;&#8211;without-isam&#8217; &#8216;&#8211;without-innodb&#8217; &#8216;&#8211;without-ndb-debug&#8217;”</p></blockquote>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年01月6号 -- <a href="http://ourapache.com/archives/27" title="php+mysql+apache编码深度解析">php+mysql+apache编码深度解析</a></li><li>2009年06月7号 -- <a href="http://ourapache.com/archives/251" title="apxs是Apache编译和安装扩展模块的工具">apxs是Apache编译和安装扩展模块的工具</a></li><li>2009年02月17号 -- <a href="http://ourapache.com/archives/142" title="在64位机器上关于Apache 2.2.3版的编译问题">在64位机器上关于Apache 2.2.3版的编译问题</a></li><li>2009年01月5号 -- <a href="http://ourapache.com/archives/19" title="重大漏洞, 让Apache上传不安全-php.rar">重大漏洞, 让Apache上传不安全-php.rar</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/13" title="单独编译apache的rewrite模块">单独编译apache的rewrite模块</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/mysql" title="mysql" rel="tag">mysql</a>, <a href="http://ourapache.com/archives/tag/nginx" title="nginx" rel="tag">nginx</a>, <a href="http://ourapache.com/archives/tag/php" title="php" rel="tag">php</a>, <a href="http://ourapache.com/archives/tag/%e7%bc%96%e8%af%91" title="编译" rel="tag">编译</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/286/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>php+mysql+apache编码深度解析</title>
		<link>http://ourapache.com/archives/27</link>
		<comments>http://ourapache.com/archives/27#comments</comments>
		<pubDate>Tue, 06 Jan 2009 06:08:31 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[编码]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=27</guid>
		<description><![CDATA[我们在做PHP项目的时候，经常会遇到中文乱码的问题，有时候编码问题还导致MYSQL的报错。中文乱码总共有三个原因 

1：APACHE服务器设置导致乱码

2：PHP，或者HTML页面编码导致中文乱码

3：MYSQL数据库的表以及字段编码导致中文乱码

我们分别从这三个部分来探究PHP程序设计中的编码问题]]></description>
			<content:encoded><![CDATA[<p> 最近蜗牛在做WEBGAME项目期间经常被可恶的乱码问题所困扰，现在基本上所有问题解决了。蜗牛把自己的经验拿出来跟大家分享。同时也为下一个项目—-数据库备份系统，做准备。</p>
<p>  好了，废话少说，直接切入：</p>
<p>  我们在做PHP项目的时候，经常会遇到中文乱码的问题，有时候编码问题还导致MYSQL的报错。中文乱码总共有三个原因</p>
<p>1：APACHE服务器设置导致乱码</p>
<p>2：<a href="http://ourapache.com/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">PHP</a>，或者HTML页面编码导致中文乱码</p>
<p>3：MYSQL数据库的表以及字段编码导致中文乱码</p>
<p>我们分别从这三个部分来探究PHP程序设计中的编码问题</p>
<p>在这之前我们要了解一些基本理论：</p>
<p>1、文件编码</p>
<p>每个文件在保存的时候都可以选择以什么编码保存，例如用WINDOWS的记事本创建一个文件可以选择ANSI 以及UTF8等等编码。我们选择了什么编码该文件就以这种编码方式保存在硬盘上。 读取该文件数据的时候也会指定一种编码来打开，如果指定的编码与文件保存的时候的编码不一样的话就会出现乱码</p>
<p>2、HTML的编码</p>
<p>在网页头部一般有这样一个&lt;HEAD&gt;区域</p>
<p>&lt;meta http-equiv=”Content-Type” content=”text/html; charset=utf-8&#8243; /&gt;<br />
这个的意思是让客户端知道，接下来输出的是html代码（text/html），并且以下输出的内容都将是utf-8编码的。如果我们用记事本创建一个HTML文件 该文件包含</p>
<p>&lt;meta http-equiv=”Content-Type” content=”text/html; charset=utf-8&#8243; /&gt;</p>
<p>但是在保存的时候却以ANSI编码格式保存，那么我们用浏览器打开这个文件时，浏览器看见META 行的UTF8编码设置后 就将文件以UTF8格式输出，而文件本来是ANSI编码，这样便出现了中文乱码。</p>
<p><strong><span style="color: #0000ff;">一：APACHE服务器编码</span></strong></p>
<p>在APACHE配置文件中有一行是编码的设置 默认的是AddDefaultCharset ISO-8859-1，大部分人认为应该将这句改为 AddDefaultCharset UTF-8 。而蜗牛认为这是误人子弟。 这项配置是告诉APACHE服务器选用什么样的编码来输出WEB页面（这样做会忽略，HTML页面中的页面编码的设置 EG：&lt;meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8&#8243; /&gt;），如果我们建立一个GB2312的页面就会出现中文乱码 。所以最好的方法是将AddDefaultCharset ISO-8859-1这一项注释掉 #AddDefaultCharset</p>
<p><strong><span style="color: #0000ff;">二：PHP编码问题</span></strong></p>
<p>php最终生成的是文本文件，而他要从数据库中取出文本数据，还要把文本数据写到数据库中。由于MYSQL并不知道PHP发送给他的是什么编码的数据，所以需要客户端PHP告诉他存取的是什么编码的数据。然后MYSQL会自动将PHP传送来的数据转换成目标编码格式的数据。</p>
<p><span style="color: #808080;">比如： PHP要将 文本数据DATE 写入到数据库字段field中，PHP发送的是UTF-8编码的数据，而DATE是以GB2312方式存储的。这时候PHP通过设置告诉MYSQL 我发的是UTF-8格式，MYSQL接到数据后 说:”我知道了，来谁专门负责将UTF-8转换成GB2312“ 于是MYSQL中的一个专门负责此事的小兵跑来 把数据拿走经过加工放到指定位置，如果PHP误将UTF-8编码的数据 当作GB2312<a href="http://ourapache.com/archives/tag/%e7%bc%96%e7%a0%81" class="st_tag internal_tag" rel="tag" title="标签 编码 下的日志">编码</a> 送给MYSQL的时候，MYSQL会叫上次那个负责UTF-8—-GB2312的小兵来负责，而小兵不管三七二十一按同样方法转换存起来，这就出现了错误，乱码就产生了。取数据的时候也一样,PHP要告诉MYSQL要取出什么样编码的数据。</span></p>
<p>PHP通过character_set_client告诉MYSQL，php存入数据库的是什么编码方式</p>
<p>PHP通过character_set_results告诉MYSQL,php需要取什么样编码的数据</p>
<p>PHP通过character_set_connection告诉MYSQL,PHP查询中的文本，使用什么编码</p>
<p>就算上面的大家都注意了，还有个问题也可能导致乱码。那就是PHP文件(生成的HTML页面）本身的编码问题</p>
<p>如果MYSQL传来的数据 编码与PHP本身编码不一致也会导致乱码</p>
<p><strong><span style="color: #0000ff;">三：MYSQL编码问题</span></strong></p>
<p>Mysql目前支持多字符集，并且，支持在不同的字符集之间转换（便于移植和支持多语言）。<br />
Mysql可以设置服务器级字符集、数据库级字符集、数据表级字符集、表列的字符集，实际上，最终使用字符集的地方是存储字符的列，比如，你设置 table1中col1列是字符类型，col1才用到了字符集，如果table1表的col2列是int类型，col2不使用字符集的概念。<br />
服务器级字符集、数据库级字符集、数据表级字符集都是为列的字符集做默认选项的。<br />
Mysql一定有一个字符集，可以通过启动时加参数指定 ，也可以编译时指定，也可以在配置文件里指定。Mysql服务器字符集，只是做为数据库级的默认值。创建数据库时，你可以指定字符集，如果没指定，就使用服务器的字符集。同理，创建表时，你可以指定表级的字符集，如果没指定，使用数据库的字符集做为表的字符集。创建列时，你可以指定某列的字符集，如果没指定，就使用表的字符集。<br />
通常情况下，您只需设置服务器级的字符集，其它的数据库级，表级，以及列级的字符集，都继承自服务器级字符集。<br />
由于UTF8是最广的字符集，所以，一般情况下，我们设置Mysql服务器级的字符集为UTF8！</p>
<p><span style="color: #ff0000;">总结：</span></p>
<p>要保证不乱码，需将三个编码统一：</p>
<p><span style="color: #ff0000;">一：是网页自身的编码</span></p>
<p><span style="color: #ff0000;">二：是HTML里指定的编码</span></p>
<p><span style="color: #ff0000;">三：是PHP告诉Mysql的编码(包括character_set_client和character_set_results)。</span></p>
<p>第一和第二个编码，如果使用DW之类的编辑器写的网页，通常是一致的，但用记事本写的网页，有可能不一致。<br />
第三个编码，需要手工通知Mysql。这步可以通过在PHP里使用mysql_query(“set names characterX”)来实现。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年08月13号 -- <a href="http://ourapache.com/archives/286" title="linux下查看nginx，apache，mysql，php的编译参数">linux下查看nginx，apache，mysql，php的编译参数</a></li><li>2009年01月5号 -- <a href="http://ourapache.com/archives/19" title="重大漏洞, 让Apache上传不安全-php.rar">重大漏洞, 让Apache上传不安全-php.rar</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/mysql" title="mysql" rel="tag">mysql</a>, <a href="http://ourapache.com/archives/tag/php" title="php" rel="tag">php</a>, <a href="http://ourapache.com/archives/tag/%e7%bc%96%e7%a0%81" title="编码" rel="tag">编码</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/27/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

