<?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>阅微堂 &#187; 数据库</title>
	<atom:link href="http://zhiqiang.org/blog/tag/%e6%95%b0%e6%8d%ae%e5%ba%93/feed" rel="self" type="application/rss+xml" />
	<link>http://zhiqiang.org/blog</link>
	<description>zhiqiang&#039;s personal blog</description>
	<lastBuildDate>Tue, 22 Jun 2010 13:08:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>动态修改Excel数据表的数据来源</title>
		<link>http://zhiqiang.org/blog/it/change-pivotcache-source.html</link>
		<comments>http://zhiqiang.org/blog/it/change-pivotcache-source.html#comments</comments>
		<pubDate>Wed, 13 Jan 2010 04:44:25 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[办公自动化]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[数据透视表]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/?p=1056</guid>
		<description><![CDATA[Excel有一个很有用的功能是直接导入外部数据库或者使用外部数据源建立数据透视表和数据透视图。但比较可惜的是，这个数据源的查询语句是静态的，它无法根据日期自动修改（比如在应用中，我们希望每天获取的外部数据都是当天最新的数据），下面两个函数是修改外部数据源的VBA代码，调用它们就可以建立动态的数据源。
' 更改数据表的来源
' wb：工作表对象
' connectionNa...]]></description>
			<content:encoded><![CDATA[<p>Excel有一个很有用的功能是直接导入外部数据库或者使用外部数据源建立数据透视表和数据透视图。但比较可惜的是，这个数据源的查询语句是静态的，它无法根据日期自动修改（比如在应用中，我们希望每天获取的外部数据都是当天最新的数据），下面两个函数是修改外部数据源的VBA代码，调用它们就可以建立动态的数据源。</p>
<pre><span style="color: #008000">' 更改数据表的来源</span>
<span style="color: #008000">' wb：工作表对象</span>
<span style="color: #008000">' connectionName：数据来源连接名称</span>
<span style="color: #008000">' strSQL：新查询语句（修改SQL的查询代码）</span>
<span style="color: #008000">' strSQLConnection：新连接语句（修改来源数据库，在对DBF数据库操作时非常有用）</span>
<span style="color: #008000">' author: zhang@zhiqiang.org, 2010</span>
<span style="color: #0000ff">Public</span> <span style="color: #0000ff">Sub</span> ChangeODBCConnection(wb <span style="color: #0000ff">As</span> Excel.Workbook, connectionName <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>, _
        <span style="color: #0000ff">Optional</span> strSQL <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> = &quot;<span style="color: #8b0000"></span>&quot;, <span style="color: #0000ff">Optional</span> strSQLConnection <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> = &quot;<span style="color: #8b0000"></span>&quot;)

    <span style="color: #0000ff">With</span> wb.Connections(connectionName).ODBCConnection
        <span style="color: #0000ff">If</span> Len(strSQLConnection) <span style="color: #0000ff">Then</span> .CommandText = SplitString(strSQLConnection)
        <span style="color: #0000ff">If</span> Len(strSQL) <span style="color: #0000ff">Then</span> .Connection = SplitString(strSQL)
    <span style="color: #0000ff">End</span> <span style="color: #0000ff">With</span>
    wb.Connections(connectionName).Refresh
<span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span>

<span style="color: #008000">' 更改数据表的来源</span>
<span style="color: #008000">' pc：数据透视表的PivotCache对象 （例如：ActiveSheet.PivotTables(1).PivotCache）</span>
<span style="color: #008000">' connectionName：数据来源连接名称</span>
<span style="color: #008000">' strSQL：新查询语句（修改SQL的查询代码）</span>
<span style="color: #008000">' strSQLConnection：新连接语句（修改来源数据库，在对DBF数据库操作时非常有用）</span>
<span style="color: #008000">' author: zhang@zhiqiang.org, 2010</span>
<span style="color: #0000ff">Public</span> <span style="color: #0000ff">Sub</span> ChangePivotConnection(pc <span style="color: #0000ff">As</span> Excel.PivotCache, <span style="color: #0000ff">Optional</span> strSQLConnect, _
        <span style="color: #0000ff">Optional</span> strSQL <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> = &quot;<span style="color: #8b0000"></span>&quot;)
    <span style="color: #0000ff">Dim</span> blnODBCConnect <span style="color: #0000ff">As</span> <span style="color: #0000ff">Boolean</span>

    <span style="color: #0000ff">With</span> pc
        <span style="color: #0000ff">If</span> .QueryType = xlODBCQuery <span style="color: #0000ff">Then</span>
            blnODBCConnect = <span style="color: #0000ff">True</span>
            <span style="color: #0000ff">If</span> Len(strSQLConnect) = 0 <span style="color: #0000ff">Then</span> strSQLConnect = .Connection
            strSQLConnect = Replace(strSQLConnect, &quot;<span style="color: #8b0000">ODBC;DSN</span>&quot;, &quot;<span style="color: #8b0000">OLEDB;DSN</span>&quot;, 1, 1, vbTextCompare)
        <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span>

        <span style="color: #0000ff">If</span> StrComp(.Connection, strSQLConnect, vbTextCompare) &lt;&gt; 0 <span style="color: #0000ff">And</span> Len(strSQLConnect) <span style="color: #0000ff">Then</span>
            .Connection = strSQLConnect
        <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span>

        <span style="color: #0000ff">If</span> StrComp(.CommandText, strSQL, vbTextCompare) &lt;&gt; 0 <span style="color: #0000ff">And</span> Len(strSQL) <span style="color: #0000ff">Then</span>
            .CommandText = (strSQL)
        <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span>

        <span style="color: #0000ff">If</span> blnODBCConnect = <span style="color: #0000ff">True</span> <span style="color: #0000ff">Then</span>
            .Connection = Replace(.Connection, &quot;<span style="color: #8b0000">OLEDB;DSN</span>&quot;, &quot;<span style="color: #8b0000">ODBC;DSN</span>&quot;, 1, 1, vbTextCompare)
        <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span>

        .Refresh
    <span style="color: #0000ff">End</span> <span style="color: #0000ff">With</span>
<span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span>

<span style="color: #008000">' 将字符串分割成短字符串的数组</span>
<span style="color: #0000ff">Private </span><span style="color: #0000ff">Function</span> SplitString(<span style="color: #0000ff">ByVal</span> s <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>) <span style="color: #0000ff">As</span> <span style="color: #0000ff">Variant</span>
    <span style="color: #0000ff">Dim</span> ss() <span style="color: #0000ff">As</span> <span style="color: #0000ff">Variant</span>
    <span style="color: #0000ff">Dim</span> i <span style="color: #0000ff">As</span> <span style="color: #0000ff">Long</span>

    <span style="color: #0000ff">ReDim</span> ss(0 <span style="color: #0000ff">To</span> Len(s) \ 200) <span style="color: #008000">' note: it is not 256</span>
    <span style="color: #0000ff">For</span> i = 0 <span style="color: #0000ff">To</span> UBound(ss)
        ss(i) = Array(Mid(s, i * 200 + 1, 200))
    <span style="color: #0000ff">Next</span> i

    SplitString = ss
<span style="color: #0000ff">End</span> <span style="color: #0000ff">Function</span></pre>
<p>以上代码在Office 2007版通过测试，其余版本未知。</p>
<div><h2>相关文章</h2><ul><li><a href="http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html">加速blog：监测和优化WordPress数据库</a> <small>在WordPress生成页面时，最消耗时间的便是数据库查询了。
监测WordPress的数据库查询
WordPress内置了数据库缓存系统，安装插件WordPress Cache Inspect，它会...</small></li><li><a href="http://zhiqiang.org/blog/it/match-date-in-vba.html">VBA中的Date类型的匹配问题</a> <small>VBA的Date类型比较奇怪。  测试：  1. 新建一个空白的Excel文档，在A1单元格输入2009-11-12。  2. 打开VBA编辑器，插入模块，增加下面这个宏  Sub test()
    MsgBo...</small></li><li><a href="http://zhiqiang.org/blog/it/archive-email-in-outlook.html">Outlook中实现Gmail中的存档功能</a> <small>时间管理中有重要的一条，保持你的收件箱整洁、干净。Gmail一个重要的创新就是Archive（存档），选中邮件后点下“archive”按钮或者按一下快捷键y，...</small></li><li><a href="http://zhiqiang.org/blog/it/vba-open-excel-in-background.html">VB中后台打开Excel文件</a> <small>某些时候需要打开Excel文件来获取或者写入数据，但又不希望跳出打开的Excel文件窗口，可以用下面的代码：      Dim eb As New excel.Application, wb as excel.Workbo...</small></li><li><a href="http://zhiqiang.org/blog/it/add-help-for-user-defined-function.html">为Excel自定义函数添加帮助信息</a> <small>函数列表界面显示选中函数的说明信息  效果图：   实现方式：  Application.MacroOptions(Macro:=&quot;UDFtest&quot...</small></li><li><a href="http://zhiqiang.org/blog/it/auto-save-attachment-in-outlook.html">自动保存Outlook邮件的附件</a> <small>在工作中定期或不定期会收到一些数据文件，然后要将它们的附件保存到自己的电脑上，下面演示如何让Outlook自动做这件事情。  首先，下面的SaveAttach...</small></li><li><a href="http://zhiqiang.org/blog/it/refer-excel-worksheet-in-vba.html">VBA中引用WorkSheet的新方法</a> <small>最近学到一招，效果不错～

在写VBA中常需要引用某个WorkSheet对象，一般通过工作表名
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet2Name")
或...</small></li><li><a href="http://zhiqiang.org/blog/it/to-get-gibberish-wordpress-move-to-dreamhost.html">搞定乱码，WordPress搬家到dreamhost</a> <small>两个月前一时冲动，花了大约80大洋买了一年的dreamhost主机。刚买的时候就试图把Blog搬到它上面去，不过由于数据库的乱码原因，一直没有成功。最近...</small></li><li><a href="http://zhiqiang.org/blog/science/computer-science/database-query-is-np-hard.html">数据库查询是NP-Hard问题</a> <small>问题来自美人他爹和Wangjianshuo's blog  一个查询的例子：NOT (AND ((C1&gt;5), OR ((C2&lt;6),(C3&lt;&gt;9))))  问题1：给出两个这样的查询Q1和Q2，如何确定Q1的结果是...</small></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2010. | <a href="http://zhiqiang.org/blog/it/change-pivotcache-source.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/change-pivotcache-source.html#comments">1&#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/change-pivotcache-source.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>数据库查询是NP-Hard问题</title>
		<link>http://zhiqiang.org/blog/science/computer-science/database-query-is-np-hard.html</link>
		<comments>http://zhiqiang.org/blog/science/computer-science/database-query-is-np-hard.html#comments</comments>
		<pubDate>Tue, 22 Dec 2009 23:43:00 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[计算机科学]]></category>
		<category><![CDATA[NP hard]]></category>
		<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/science/computer-science/database-query-is-np-hard.html</guid>
		<description><![CDATA[问题来自美人他爹和Wangjianshuo's blog
一个查询的例子：NOT (AND ((C1&#62;5), OR ((C2&#60;6),(C3&#60;&#62;9))))
问题1：给出两个这样的查询Q1和Q2，如何确定Q1的结果是否是Q2结果的子集？
上面两篇文章主要是讨论实际工作中怎么解决问题1。下面从理论上分析一下这个问题。
问题2：判断Q1查询结果是否为空集。
在问题1中让Q2查询结果为空集，故问题1是比问题2更难的一个问题。
论断：问题2...]]></description>
			<content:encoded><![CDATA[<p>问题来自<a href="http://www.meirendaddy.com/blog/?p=694">美人他爹</a>和<a href="http://home.wangjianshuo.com/archives/20091213_i_am_not_computer_science_major.htm">Wangjianshuo's blog</a></p>
<p>一个查询的例子：NOT (AND ((C1&gt;5), OR ((C2&lt;6),(C3&lt;&gt;9))))</p>
<p>问题1：给出两个这样的查询Q1和Q2，如何确定Q1的结果是否是Q2结果的子集？</p>
<p>上面两篇文章主要是讨论实际工作中怎么解决问题1。下面从理论上分析一下这个问题。</p>
<p>问题2：判断Q1查询结果是否为空集。</p>
<p>在问题1中让Q2查询结果为空集，故问题1是比问题2更难的一个问题。</p>
<p>论断：问题2是<a href="http://zhiqiang.org/blog/tag/np-hard">NP-hard</a>的。</p>
<p>证明：从3SAT问题很容易规约到问题2。</p>
<p>结论：问题1是NP-Hard的，除非NP=P，不可能有多项式级别的解。也就是理论上而言，解决上面的问题除了枚举没有别的好方法了。</p>
<p>当然以上只是理论，实际应用中，<img src="http://zhiqiang.org/blog/wp-content/cache/tex_ed11dc9af96ff98159e9c06973c09457.png" style="vertical-align:middle; padding-bottom:1px;" class="tex" alt="3^n" />的计算速度和<img src="http://zhiqiang.org/blog/wp-content/cache/tex_d1db0d9c696a8c056e7117dbbb4ef6db.png" style="vertical-align:middle; padding-bottom:1px;" class="tex" alt="2^n" />的计算速度还是有很大的区别。如何解决NP-Hard问题也是一个被广泛研究的课题，毕竟实际工作中很多问题都是NP-Hard的。</p>
<div><h2>相关文章</h2><ul><li><a href="http://zhiqiang.org/blog/science/computer-science/np-hard.html">TCS：NP-hard</a> <small>好久没有写我的理论计算机初步系列了，其实复杂性这一块，虽然平时经常遇到，但由于问题都过于本质和困难，想这方面问题的时间反而不多。Ko教...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html">加速blog：监测和优化WordPress数据库</a> <small>在WordPress生成页面时，最消耗时间的便是数据库查询了。
监测WordPress的数据库查询
WordPress内置了数据库缓存系统，安装插件WordPress Cache Inspect，它会...</small></li><li><a href="http://zhiqiang.org/blog/science/computer-science/minesweeper-is-np-complete.html">扫雷是NP完全问题</a> <small>本科时有同学扫雷最快可以在60多秒完成高级难度，让我这种最快130秒的人非常惭愧，当时就想着编一个全自动的扫雷程序，不过一直也没写。今天才...</small></li><li><a href="http://zhiqiang.org/blog/science/computer-science/most-windows-game-are-np-complete.html">Windows游戏中的NP完全问题</a> <small>上篇文章扫雷是NP完全问题之后，You Xu提到＂不光扫雷是NP 完全问题，空当接龙问题也极有可能是一个NP完全问题。目前最好的通用 planner只能解半副牌...</small></li><li><a href="http://zhiqiang.org/blog/science/computer-science/introduce-probabilistic-checkable-proof.html">PCP - Probabilistic Checkable Proof</a> <small>PS: PCP可以说是理论计算机领域近20年来的最重要的结果之一，它给了NP问题一个新的刻画，并且提供了一种证明近似算法下界的方法。下面是yijia写的PCP...</small></li><li><a href="http://zhiqiang.org/blog/it/change-pivotcache-source.html">动态修改Excel数据表的数据来源</a> <small>Excel有一个很有用的功能是直接导入外部数据库或者使用外部数据源建立数据透视表和数据透视图。但比较可惜的是，这个数据源的查询语句是静态的...</small></li><li><a href="http://zhiqiang.org/blog/it/to-get-gibberish-wordpress-move-to-dreamhost.html">搞定乱码，WordPress搬家到dreamhost</a> <small>两个月前一时冲动，花了大约80大洋买了一年的dreamhost主机。刚买的时候就试图把Blog搬到它上面去，不过由于数据库的乱码原因，一直没有成功。最近...</small></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2009. | <a href="http://zhiqiang.org/blog/science/computer-science/database-query-is-np-hard.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/computer-science/database-query-is-np-hard.html#comments">2 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/computer-science/database-query-is-np-hard.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>加速blog：监测和优化WordPress数据库</title>
		<link>http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html</link>
		<comments>http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html#comments</comments>
		<pubDate>Thu, 27 Dec 2007 08:39:01 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[网站提速]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/?p=730</guid>
		<description><![CDATA[在WordPress生成页面时，最消耗时间的便是数据库查询了。
监测WordPress的数据库查询
WordPress内置了数据库缓存系统，安装插件WordPress Cache Inspect，它会告诉你这个系统的效率（命中效率），主要为下面四个指标：
Cold Cache Hits 
This is the number of cached items that were loaded from disk. 
Warm Cache Hits 
This is the number of cached items accessed that were already in memory 
Cache Misses 
This is the number of items that had...]]></description>
			<content:encoded><![CDATA[<p>在WordPress生成页面时，最消耗时间的便是数据库查询了。</p>
<h3>监测WordPress的数据库查询</h3>
<p>WordPress内置了数据库缓存系统，安装插件<a href="http://blog.ftwr.co.uk/wordpress/wp-cache-inspect/">WordPress Cache Inspect</a>，它会告诉你这个系统的效率（命中效率），主要为下面四个指标：</p>
<dt><strong>Cold Cache Hits</strong> </dt>
<dd>This is the number of cached items that were loaded from disk. </dd>
<dt><strong>Warm Cache Hits</strong> </dt>
<dd>This is the number of cached items accessed that were already in memory </dd>
<dt><strong>Cache Misses</strong> </dt>
<dd>This is the number of items that had to be fetched from the db as they were not in the cache. </dd>
<dt><strong>Loaded data</strong> </dt>
<dd>This lists the type and amount of data loaded into memory from that currently stored within the cache..</p>
<h3>define('ENABLE_CACHE', true);</h3>
<p>把这条语句加入WordPress的配置文件wp-config.php里，WordPress便会以文本的方式缓存一些数据库查询的结果到/wp-content/cache/目录下。注意保持这个目录可写。</p>
<p>试试看效果再用。因为这玩意儿是用磁盘Cache保持数据库查询结果。但某些服务器上，磁盘IO比较慢，比如在dreamhost上就不推荐用这种方式。</p>
<h3>显示所有数据库查询语句和消耗时间</h3>
<p>在wp-config.php文件里添加<a style="color: #ffa500" href="http://www.php.net/define">define</a>('<span style="color: #8b0000;">SAVEQUERIES</span>', <a style="color: #0000ff" href="http://www.php.net/true">true</a>);<span style="color: #0000ff;">，</span>再在footer.php文件的尾部加上一句<span style="color: #0000ff;">&lt;?</span>php <a style="color: #ffa500" href="http://www.php.net/var_dump">var_dump</a>($wpdb-&gt;queries); <span style="color: #0000ff;">?&gt;</span> 。就可以在页面源代码的尾部找到整个页面执行过程中所提交的所有MySQL查询语句了。数组里每一项都包含一个string和一个float，string存储查询语句，float存储查询时间。</p>
<p>参考：<a href="http://yskin.net/2006/11/wordpress-sql-statement.html">查看WordPress页面执行过程中提交的SQL查询语句</a>。</p>
<h3>比较耗时的数据库语句</h3>
<p><a href="http://www.21andy.com/blog/20060813/374.html">WordPress执行效率问题</a>作者作了一个测试，大家可以看一下具体有什么问题，与自己的做一个对照。我提一下我遇到过的比较慢的查询语句。</p>
<h4>分类和tag相关的都比较消耗时间</h4>
<p>比较消耗时间的基本上都与分类表相关的三个数据表相关。特别是我用的那个相关文章查询，基本上占总查询时间的20%（优化后）。我比较期待快速或者带Cache的相关文章的插件。</p>
<h4>DESC wp_comments</h4>
<p>我不知道这个语句干啥的，经常很慢，所以我把产生它的插件"subscribe comments"插件直接禁用了，反正那个插件提供的功能就没几个人用。</p>
</dd>
<p>持续更新ing...</p>
<div><h2>相关文章</h2><ul><li><a href="http://zhiqiang.org/blog/science/computer-science/database-query-is-np-hard.html">数据库查询是NP-Hard问题</a> <small>问题来自美人他爹和Wangjianshuo's blog  一个查询的例子：NOT (AND ((C1&gt;5), OR ((C2&lt;6),(C3&lt;&gt;9))))  问题1：给出两个这样的查询Q1和Q2，如何确定Q1的结果是...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-your-blog.html">加速blog：序</a> <small>这是一个介绍如何提速blog的系列文章，特别是基于WordPress的blog。通过这些方法，你我完全能做到一个飞速的blog，至少要比与你同服务器上的其它blog要...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-cache-on-server.html">加速blog：服务器端的中转和缓存</a> <small>前面已经提到了浏览器端的缓存，通过适当的Header可以建议和命令浏览器缓存页面内容比如javascript, css, 图片等。这里的服务器端的缓存又是什么意思...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-http-headers.html">加速blog：HTTP Header</a> <small>本文隶属加速blog系列  HTTP请求和相应Header  一个经典的HTTP连接是，读者通过浏览器（下称为浏览器端），向服务器（下称为服务器端）申请浏览某网页...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-reduce-plugins.html">加速blog：减少和优化插件</a> <small>尽量少用含javascript和css的插件
很多插件作者需要为blog的慢速度负责。插件作者随意地往'wp_head'里安插js和css，导致很多blog的head部分越来越臃肿。

...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-analysis-your-website.html">加速blog：速度检测</a> <small>本文隶属加速blog系列

既然我们要谈加速blog，第一重要的是给blog的速度一个量化的评价。

Firefox的fasterfox插件会在Firefox的右下角给出每个网页的载...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress.html">加速blog：优化WordPress程序效率</a> <small>这里本质上要谈的还是优化数据库的效率，不过是改写WordPress的代码使得降低数据库查询次数。
get_permalink函数
get_permalink函数非常好用，get_permalink($i...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-choose-appropriate-server.html">加速blog：选择合适的服务器</a> <small>要想打造一个响应快速的blog，一个快速的服务器（虚拟主机空间）是必不可少的。其实这才是决定因素，因为这可能会导致速度在数量级上的差距（我...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-cache-wordpress.html">加速blog：WordPress的缓存和静态化</a> <small>WordPress消耗时间最多的便是数据库的查询，所以缓存是一个比较好的解决方案。WordPress强大的'hook'机制，使得可以为之建立强大的缓存机制，从缓存数...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-factors-of-slowness.html">加速blog：网站响应缓慢的因素</a> <small>本文隶属加速blog系列 

为什么有的网站即点即开，有些却慢得要死？影响网站速度的因素有但不限于下面这些：许多因素会影响到网页初次访问的响...</small></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2007. | <a href="http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html#comments">2 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>搞定乱码，WordPress搬家到dreamhost</title>
		<link>http://zhiqiang.org/blog/it/to-get-gibberish-wordpress-move-to-dreamhost.html</link>
		<comments>http://zhiqiang.org/blog/it/to-get-gibberish-wordpress-move-to-dreamhost.html#comments</comments>
		<pubDate>Mon, 03 Jul 2006 12:17:48 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[记事本]]></category>
		<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[搬家]]></category>
		<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/359.html</guid>
		<description><![CDATA[两个月前一时冲动，花了大约80大洋买了一年的dreamhost主机。刚买的时候就试图把Blog搬到它上面去，不过由于数据库的乱码原因，一直没有成功。最近，多个电信的朋友告诉我我的Blog速度&#8220;慢得不能忍受&#8221;，今天下午下定决心搞定数据库，哪知道一下子就弄了4个小时，到现在才基本上搞定。现在正式进入测试期，欢迎报告Bug和异常情况。
先说一下我是怎么解决数据库...]]></description>
			<content:encoded><![CDATA[<p>两个月前一时冲动，花了大约80大洋买了一年的<a href="http://www.dreamhost.com">dreamhost主机</a>。刚买的时候就试图把Blog搬到它上面去，不过由于数据库的乱码原因，一直没有成功。最近，多个电信的朋友告诉我我的Blog速度&ldquo;慢得不能忍受&rdquo;，今天下午下定决心搞定数据库，哪知道一下子就弄了4个小时，到现在才基本上搞定。现在正式进入测试期，欢迎报告Bug和异常情况。</p>
<p>先说一下我是怎么解决数据库乱码问题的。最开始的时候在phpmyadmin里面直接导入备份文件（使用WordPress自带的database backup生成），最后文章里面大部分显示正常，但是间或的有些汉字变成了乱码（在FireFox下变成两个?号）。在无数次失败的尝试和Baidu的帮助下，最后找到解决方案：</p>
<ol>
<li>使用WordPress自带的database backup生成备份文件（打开这个文件，里面中文是正常的，而如果直接从phpmyadmin里面导出数据库，中文都是乱码）。 </li>
<li>在phpMyadmin中设定MySQL 字符集: UTF-8 Unicode (utf8) （一般来说默认就是这个） </li>
<li>在phpMyadmin中设定MySQL 连接校对: utf8_general_ci </li>
<li><font color="#ff0000">用文本编辑器如EditPlus 打开备份的数据库文件，查找&quot;DEFAULT CHARSET=latin1&quot; 用&quot;DEFAULT CHARSET=utf8&quot;替换。</font> </li>
<li>用phpMyadmin导入上面修改过的备份文件。 </li>
<li>修改wp-includes/wp-db.php內的资料连线设定。详细的修改方式是这样的：<br />$this-&gt;dbh = @mysql_connect($dbhost,$dbuser,$dbpassword);<br />//加上下面这行<br /><code>$this-&gt;query(&quot;SET NAMES 'utf8'&quot; );</code> </li>
</ol>
<p>这样做之后，不但页面上没有乱码，在数据库里面也可以直接看到中文。另外，在解决过程中得到了<a target="_blank" href="http://lucifr.com">Lucifer</a>和<a target="_blank" href="http://www.sunxiunan.com/">Sunwell</a>帮助，关键的一步从<a target="_blank" href="http://www.jekee.com/wordpress%e6%81%a2%e5%a4%8d%e6%95%b0%e6%8d%ae%e5%ba%93%e5%90%8e%e4%b9%b1%e7%a0%81%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3.html">wordpress恢复数据库后乱码问题的解决</a>看来的，一并表示感谢。</p>
<p>我和Dreamhost：</p>
<ul>
<li>我上Dreamhost还是太慢了，特别是它的FTP，无法忍受。 </li>
<li>Dreamhost的CPU速度比我原来的实验室的服务器还要慢，看看页面生成时间，有时候竟然需要2秒以上，郁闷。 </li>
<li>Dreamhost的服务器在国外，教育网访问需要代理，包括我自己，:(。 </li>
<li>不用担心备案问题了，不过我担心Dreamhost整体被封。 </li>
<li>十个月后空间到期后咋办呢？对我来说，搬家很快的，拎着数据库跑就行了。图片啥的我都放到Flickr和Picasa Web上了。不过寻找新空间是个大问题，暂时不管了。 </li>
</ul>
<p>另外，Dreamhost的unix主机的文件名是分大小写的，结果导致我有些ajax程序异常，不过现在已修正。</p>
<div><h2>相关文章</h2><ul><li><a href="http://zhiqiang.org/blog/it/move-to-the-blog-server-bluehost.html">blog服务器搬家到bluehost</a> <small>去年5月份买的Dreamhost快要到期了，趁cosβ组织Bluehost分享的机会，提前搬到了bluehost。 bluehost和dreamhost是中国独立blog用得最多的两个主机空间，而bluehost...</small></li><li><a href="http://zhiqiang.org/blog/science/computer-science/move-blogbus-data-to-wordpress.html">BlogBus搬家文件转WordPress导入文件</a> <small>  最近给某blog做了一次搬家，从Sina转到WordPress独立博客，网上已经有很多工具和方法，但可用而且耗用的不多，总是有一些乱七八糟的问题。这里说一...</small></li><li><a href="http://zhiqiang.org/blog/it/wordpress-21-solution-can-not-remove-the-article-upgrade-to-213.html">WordPress 2.1无法删除文章解决方法 &amp; 升级到2.1.3</a> <small>如果你在升级WordPress到2.1之后遇到以下情况：  无法删除文章(post)在文章列表的"Edit"链接旁边，看不到该有的"Delete"链接。在Edit文章界面，点击"Delete thi...</small></li><li><a href="http://zhiqiang.org/blog/it/wordpress-the-revised-calendar-own-style.html">修改wordpress的自带日历式样</a> <small>wordpress自带了一个日历函数get_calendar()，可以显示每天各发了哪些文章（把鼠标移到日期上即可看到），是个很实用的函数。可是它原来的式样太丑了...</small></li><li><a href="http://zhiqiang.org/blog/it/reading-church-wordpress-plug-in-system-architecture-use.html">阅微堂系统架构 &#038; WordPress插件使用情况</a> <small>本系统使用了以下插件：

	Ajax Comments-Reply: 可以在迴響之後跟隨回覆，使用Ajax無刷新。经过一些修改后，实现本系统的MSN Spaces风格的页面ajax显示和...</small></li><li><a href="http://zhiqiang.org/blog/it/let-windows-live-writer-support-tag-of-wordpress-23.html">Windows Live Writer支持WordPress 2.3的tag的方法（不用插件）</a> <small>下载这个文件，解压后上传到blog的根目录，之后WLW编辑区域下面的高级选项里多出了一个keywords选项，里面就对应着WP2.3的Tag!  不是我写的...</small></li><li><a href="http://zhiqiang.org/blog/it/wordpress-create-the-most-efficient-of-all-stations-browsing.html">打造最快捷的wordpress的全站浏览方式</a> <small>我们有很多种方式浏览全站文章，主页面往前翻页，通过察看分类和按日期存档察看，或者通过搜索查找自己敢兴趣的东西。这些方法的缺陷就是太慢...</small></li><li><a href="http://zhiqiang.org/blog/it/dreamhost-on-gzip-cache.html">Dreamhost上的GZIP &#038; Cache</a> <small>用WordPress的都知道，WordPress可以打开GZIP传输，压缩比率能达到60%到80%。下表是本blog首页在Web Page Analyzer上的测试报告，此页面上包括css, js所有东西加...</small></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html">加速blog：监测和优化WordPress数据库</a> <small>在WordPress生成页面时，最消耗时间的便是数据库查询了。
监测WordPress的数据库查询
WordPress内置了数据库缓存系统，安装插件WordPress Cache Inspect，它会...</small></li><li><a href="http://zhiqiang.org/blog/it/wordspew-plug-litter-message-solution.html">wordspew插件的垃圾留言的解决办法</a> <small>wordspew插件可以给Blog添加一个实时的ajax聊天窗口，也可以用来当作一个简单留言板，具体效果可见本blog左侧栏的在线聊天模块。本来一直用得挺好的...</small></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2006. | <a href="http://zhiqiang.org/blog/it/to-get-gibberish-wordpress-move-to-dreamhost.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/to-get-gibberish-wordpress-move-to-dreamhost.html#comments">46 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/to-get-gibberish-wordpress-move-to-dreamhost.html/feed</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
	</channel>
</rss>
