﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-编程自动化-随笔分类-数据库</title><link>http://www.cppblog.com/AutomateProgram/category/17097.html</link><description>当音乐和传说在深夜中沉寂后，程序的每个字符还在跳动！</description><language>zh-cn</language><lastBuildDate>Sat, 21 Jul 2012 01:40:53 GMT</lastBuildDate><pubDate>Sat, 21 Jul 2012 01:40:53 GMT</pubDate><ttl>60</ttl><item><title>mysql账号权限管理和账号设置</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/06/14/178780.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 14 Jun 2012 04:02:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/06/14/178780.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/178780.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/06/14/178780.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/178780.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/178780.html</trackback:ping><description><![CDATA[<div style="layout-grid:  15.6pt none" class="Section0">
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 15pt; font-weight: bold; mso-spacerun: 'yes'">一．</span><span style="font-style: normal; font-family: 'Verdana'; font-size: 15pt; font-weight: bold; mso-spacerun: 'yes'">权限查看</span><span style="font-family: 'Times New Roman'; font-size: 15pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 15pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">mysql&gt;&nbsp;show&nbsp;grants&nbsp;for&nbsp;<font face="Times New Roman">&#8216;</font><font face="Verdana">root</font><font face="Times New Roman">&#8217;</font><font face="Verdana">@'localhost</font><font face="Times New Roman">&#8217;&nbsp;</font><font face="Verdana">;</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">+<font face="Times New Roman">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</font><font face="Verdana">-+</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">|&nbsp;Grants&nbsp;for&nbsp;root@localhost&nbsp;|</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">+<font face="Times New Roman">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</font><font face="Verdana">-+</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">|&nbsp;GRANT&nbsp;ALL&nbsp;PRIVILEGES&nbsp;ON&nbsp;*.*&nbsp;TO&nbsp;<font face="Times New Roman">&#8216;</font><font face="Verdana">root</font><font face="Times New Roman">&#8217;</font><font face="Verdana">@'localhost</font><font face="Times New Roman">&#8217;&nbsp;</font><font face="Verdana">WITH&nbsp;GRANT&nbsp;OPTION&nbsp;|</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">+<font face="Times New Roman">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</font><font face="Verdana">-+</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">二．</span><span style="font-style: normal; font-family: 'Verdana'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">权限设置</span><span style="font-family: 'Times New Roman'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">1.</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">创建账号或者赋予权限</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;privileges&nbsp;(columns)&nbsp;ON&nbsp;what&nbsp;TO&nbsp;user&nbsp;IDENTIFIED&nbsp;BY&nbsp;"password"&nbsp;WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT语句的语法看上去像这样：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;privileges&nbsp;(columns)&nbsp;ON&nbsp;what&nbsp;TO&nbsp;user&nbsp;IDENTIFIED&nbsp;BY&nbsp;"password"&nbsp;WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">要使用该语句，你需要填写下列部分：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">privileges</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;授予用户的权限，下表列出可用于GRANT语句的权限指定符：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　权限指定符&nbsp;权限允许的操作&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Alter</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　　　修改表和索引&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Create</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;创建数据库和表&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Delete</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;删除表中已有的记录&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Drop</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　&nbsp;抛弃（删除）数据库和表&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">INDEX</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;创建或抛弃索引&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Insert</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;向表中插入新行&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">REFERENCE</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　未用&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Select</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　　　&nbsp;检索表中的记录&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Update</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;修改现存表记录&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">FILE</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　　　读或写服务器上的文件&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">PROCESS</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　&nbsp;查看服务器中执行的线程信息或杀死线程&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">RELOAD</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　重载授权表或清空日志、主机缓存或表缓存。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">SHUTDOWN</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　&nbsp;关闭服务器&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">ALL</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　　　所有；ALL&nbsp;PRIVILEGES同义词&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">USAGE</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　特殊的&#8220;无权限&#8221;权限</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　上表显示在第一组的权限指定符适用于数据库、表和列，第二组数管理权限。一般，这些被相对严格地授权，因为它们允许用户影响服务器的操作。第三组权限特殊，ALL意味着&#8220;所有权限&#8221;，UASGE意味着无权限，即创建用户，但不授予权限。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">columns</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　权限运用的列，它是可选的，并且你只能设置列特定的权限。如果命令有多于一个列，应该用逗号分开它们。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">what</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　权限运用的级别。权限可以是全局的（适用于所有数据库和所有表）、特定数据库（适用于一个数据库中的所有表）或特定表的。可以通过指定一个columns字句是权限是列特定的。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">user&nbsp;</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　权限授予的用户，它由一个用户名和主机名组成。在MySQL中，你不仅指定谁能连接，还有从哪里连接。这允许你让两个同名用户从不同地方连接。&nbsp;MySQL让你区分他们，并彼此独立地赋予权限。MySQL中的一个用户名就是你连接服务器时指定的用户名，该名字不必与你的Unix登录名或&nbsp;Windows名联系起来。缺省地，如果你不明确指定一个名字，客户程序将使用你的登录名作为MySQL用户名。这只是一个约定。你可以在授权表中将该名&nbsp;字改为nobody，然后以nobody连接执行需要超级用户权限的操作。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">password&nbsp;</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　赋予用户的口令，它是可选的。如果你对新用户没有指定IDENTIFIED&nbsp;BY子句，该用户不赋给口令（不安全）。对现有用户，任何你指定的口令将代替老口令。如果你不指定口令，老口令保持不变，当你用IDENTIFIED&nbsp;BY时，口令字符串用改用口令的字面含义，GRANT将为你编码口令，不要你用SET&nbsp;PASSWORD&nbsp;那样使用password()函数。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">子句是可选的。如果你包含它，用户可以授予权限通过GRANT语句授权给其它用户。你可以用该子句给与其它用户授权的能力。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">注意：</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">用户名、口令、数据库和表名在授权表记录中是大小写敏感的，主机名和列名不是。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　一般地，你可以通过询问几个简单的问题来识别GRANT语句的种类：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　谁能连接，从那儿连接？&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　用户应该有什么级别的权限，他们适用于什么？&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　用户应该允许管理权限吗？&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　下面就讨论一些例子。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　1.1&nbsp;谁能连接，从那儿连接？&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　你可以允许一个用户从特定的或一系列主机连接。有一个极端，如果你知道降职从一个主机连接，你可以将权限局限于单个主机：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;boris@localhost&nbsp;IDENTIFIED&nbsp;BY&nbsp;"ruby"</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;fred@res.mars.com&nbsp;IDENTIFIED&nbsp;BY&nbsp;"quartz"</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　(samp_db.*意思是&#8220;samp_db数据库的所有表)另一个极端是，你可能有一个经常旅行并需要能从世界各地的主机连接的用户max。在这种情况下，你可以允许他无论从哪里连接：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;max@%&nbsp;IDENTIFIED&nbsp;BY&nbsp;"diamond"&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　&#8220;%&#8221;字符起通配符作用，与LIKE模式匹配的含义相同。在上述语句中，它意味着&#8220;任何主机&#8221;。所以max和max@%等价。这是建立用户最简单的方法，但也是最不安全的。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　其中，你可以允许一个用户从一个受限的主机集合访问。例如，要允许mary从snake.net域的任何主机连接，用一个%.snake.net主机指定符：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;mary@.snake.net&nbsp;IDENTIFIED&nbsp;BY&nbsp;"quartz";&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　如果你喜欢，用户标识符的主机部分可以用IP地址而不是一个主机名来给定。你可以指定一个IP地址或一个包含模式字符的地址，而且，从MySQL&nbsp;3.23，你还可以指定具有指出用于网络号的位数的网络掩码的IP号：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;boris@192.168.128.3&nbsp;IDENTIFIED&nbsp;BY&nbsp;"ruby"&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;fred@192.168.128.%&nbsp;IDENTIFIED&nbsp;BY&nbsp;"quartz"&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;rex@192.168.128.0/17&nbsp;IDENTIFIED&nbsp;BY&nbsp;"ruby"</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　第一个例子指出用户能从其连接的特定主机，第二个指定对于C类子网192.168.128的IP模式，而第三条语句中，192.168.128.0/17指定一个17位网络号并匹配具有192.168.128头17位的IP地址。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　1.2&nbsp;用户应该有什么级别的权限和它们应该适用于什么？</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　你可以授权不同级别的权限，全局权限是最强大的，因为它们适用于任何数据库。要使ethel成为可做任何事情的超级用户，包括能授权给其它用户，发出下列语句：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;*.*&nbsp;TO&nbsp;ethel@localhost&nbsp;IDENTIFIED&nbsp;BY&nbsp;"coffee"&nbsp;WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　ON子句中的*.*意味着&#8220;所有数据库、所有表&#8221;。从安全考虑，我们指定ethel只能从本地连接。限制一个超级用户可以连接的主机通常是明智的，因为它限制了试图破解口令的主机。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　有些权限（FILE、PROCESS、RELOAD和SHUTDOWN）是管理权限并且只能用"ON&nbsp;*.*"全局权限指定符授权。如果你愿意，你可以授权这些权限，而不授权数据库权限。例如，下列语句设置一个flush用户，他只能发出flush语句。&nbsp;这可能在你需要执行诸如清空日志等的管理脚本中会有用：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;RELOAD&nbsp;ON&nbsp;*.*&nbsp;TO&nbsp;flushl@localhost&nbsp;IDENTIFIED&nbsp;BY&nbsp;"flushpass"&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　一般地，你想授权管理权限，吝啬点，因为拥有它们的用户可以影响你的服务器的操作。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">数据库级权限适用于一个特定数据库中的所有表，它们可通过使用ON&nbsp;db_name.*子句授予：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db&nbsp;TO&nbsp;bill@racer.snake.net&nbsp;INDETIFIED&nbsp;BY&nbsp;"rock"&nbsp;GRANT&nbsp;Select&nbsp;ON&nbsp;samp_db&nbsp;TO&nbsp;ro_user@%&nbsp;INDETIFIED&nbsp;BY&nbsp;"rock"</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　第一条语句向bill授权samp_db数据库中所有表的权限，第二条创建一个严格限制访问的用户ro_user（只读用户），只能访问samp_db数据库中的所有表，但只有读取，即用户只能发出Select语句。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　你可以列出一系列同时授予的各个权限。例如，如果你想让用户能读取并能修改现有数据库的内容，但不能创建新表或删除表，如下授予这些权限：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;Select,Insert,Delete,Update&nbsp;ON&nbsp;samp_db&nbsp;TO&nbsp;bill@snake.net&nbsp;INDETIFIED&nbsp;BY&nbsp;"rock"</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　对于更精致的访问控制，你可以在各个表上授权，或甚至在表的每个列上。当你想向用户隐藏一个表的部分时，或你想让一个用户只能修改特定的列时，列特定权限非常有用。如：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;Select&nbsp;ON&nbsp;samp_db.member&nbsp;TO&nbsp;bill@localhost&nbsp;INDETIFIED&nbsp;BY&nbsp;"rock"</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;Update&nbsp;(expiration)&nbsp;ON&nbsp;samp_db.&nbsp;member&nbsp;TO&nbsp;bill@localhost&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　第一条语句授予对整个member表的读权限并设置了一个口令，第二条语句增加了Update权限，当只对expiration列。没必要再指定口令，因为第一条语句已经指定了。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　如果你想对多个列授予权限，指定一个用逗号分开的列表。例如，对assistant用户增加member表的地址字段的Update权限，使用如下语句，新权限将加到用户已有的权限中：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;Update&nbsp;(street,city,state,zip)&nbsp;ON&nbsp;samp_db&nbsp;TO&nbsp;assistant@localhost&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">1.3&nbsp;用户应该被允许管理权限吗？</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　你可以允许一个数据库的拥有者通过授予数据库上的所有拥有者权限来控制数据库的访问，在授权时，指定WITH&nbsp;GRANT&nbsp;OPTION。例如：如果你想让alicia能从big.corp.com域的任何主机连接并具有sales数据库中所有表的管理员权限，你可以用如下&nbsp;GRANT语句：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;sales.*&nbsp;TO&nbsp;alicia@%.big.corp.com&nbsp;INDETIFIED&nbsp;BY&nbsp;"applejuice"&nbsp;WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　在效果上WITH&nbsp;GRANT&nbsp;OPTION子句允许你把访问授权的权利授予另一个用户。要注意，拥有GRANT权限的两个用户可以彼此授权。如果你只给予了第一个用户Select权&nbsp;限，而另一个用户有GRANT加上Select权限，那么第二个用户可以是第一个用户更&#8220;强大&#8221;。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">常见语句：</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">常见账号，并赋予权限</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">GRANT&nbsp;SELECT,INSERT,UPDATE,DELETE,CREATE,DROP&nbsp;ON&nbsp;</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">db1</span><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">.*&nbsp;TO&nbsp;'linpp'@'192.168.40.111'&nbsp;IDENTIFIED&nbsp;BY&nbsp;'qq';</span><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">进一步赋予权限</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">GRANT&nbsp;SELECT&nbsp;ON&nbsp;</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">db2</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">.*&nbsp;TO&nbsp;'linpp'@'192.168.40.111';</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">2.</span><span style="font-style: normal; font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">撤权并删除用户</span><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">要取消一个用户的权限，使用REVOKE语句。REVOKE的语法非常类似于GRANT语句，除了TO用FROM取代并且没有INDETIFED&nbsp;BY和WITH&nbsp;GRANT&nbsp;OPTION子句：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">REVOKE&nbsp;privileges&nbsp;(columns)&nbsp;ON&nbsp;what&nbsp;FROM&nbsp;user&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　user部分必须匹配原来GRANT语句的你想撤权的用户的user部分。privileges部分不需匹配，你可以用GRANT语句授权，然后用REVOKE语句只撤销部分权限。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　REVOKE语句只删除权限，而不删除用户。即使你撤销了所有权限，在user表中的用户记录依然保留，这意味着用户仍然可以连接服务器。要完全删除一个用户，你必须用一条Delete语句明确从user表中删除用户记录：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">%mysql&nbsp;-u&nbsp;root&nbsp;mysqlmysql&gt;Delete&nbsp;FROM&nbsp;user&nbsp;-&gt;Where&nbsp;User="user_name"&nbsp;and&nbsp;Host="host_name";mysql&gt;FLUSH&nbsp;PRIVILEGES;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">从ip为 * 以后限制ip 可先删除账号，在构建有ip限制的用户，用户权限不会改变，或者直接修改user表的host<br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　Delete语句删除用户记录，而FLUSH语句告诉服务器重载授权表。（当你使用GRANT和REVOKE语句时，表自动重载，而你直接修改授权表时不是。）</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">常见语句：</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;REVOKE&nbsp;UPDATE&nbsp;ON&nbsp;</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">db1</span><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">.*&nbsp;FROM&nbsp;'linpp'@'192.168.40.111';</span><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">三.</span><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">mysql&nbsp;修改密码</span><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">use&nbsp;mysql</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">u</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">pdate&nbsp;user&nbsp;set&nbsp;password=password('你的密码')&nbsp;where&nbsp;User='root';</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">flush&nbsp;privileges;</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">四．</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">涉及到账号和权限的表</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">User</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行就是一个用户账号以及用户的全部权限</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Db</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行包含了某些用户在数据库级权限</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Host</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行包含了用户从指定主机登陆过来时它在一个数据库里的所有权限，这个条目会与db表里的条目合并起来使用。虽然它是作为授权表罗列出来的，但是你无法使用grant,revoke等命令修改这个主机表，你只能手动添加和删除其中的条目。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">建议你不要动这张表。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Tables_priv</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行宝航了指定用户和表的表级别上的权限，也包括了视图和权限在内。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Columms_priv </span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行指定了用户和列的列的级别上的权限。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Procs_priv</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行包含了指定用户和存储程序的权限。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p></div><!--EndFragment-->  <img src ="http://www.cppblog.com/AutomateProgram/aggbug/178780.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-06-14 12:02 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/06/14/178780.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>内存数据库 memcached介绍，windows下配置安装，客户端入门</title><link>http://www.cppblog.com/AutomateProgram/archive/2011/06/29/149762.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Wed, 29 Jun 2011 09:20:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2011/06/29/149762.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/149762.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2011/06/29/149762.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/149762.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/149762.html</trackback:ping><description><![CDATA[<span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="line-height: 24px; font-family: arial, 宋体, sans-serif; font-size: 14px" class="Apple-style-span"><strong><br />Memcached是什么?</strong></span></span><br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="line-height: 24px; font-family: arial, 宋体, sans-serif; font-size: 14px" class="Apple-style-span">Memcached 是一个高性能的分布式<a style="color: rgb(19,110,194); text-decoration: underline" href="http://baike.baidu.com/view/1082.htm" target="_blank">内存</a>对象缓存系统，用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数，从而提供动态、数据库驱动网站的速度。Memcached基于一个存储键/值对的hashmap。其守护进程（daemon ）是用C写的，但是<a style="color: rgb(19,110,194); text-decoration: underline" href="http://baike.baidu.com/view/930.htm" target="_blank">客户端</a>可以用任何语言来编写，并通过memcached协议与守护进程通信。但是它并不提供冗余（例如，复制其hashmap条目）；当某个服务器S停止运行或崩溃了，所有存放在S上的键/值对都将丢失。 
<div style="line-height: 14px; overflow-x: hidden; overflow-y: hidden; height: 14px; font-size: 12px" class="spctrl"></div>　　Memcached由Danga Interactive开发，其最新版本发布于2010年，作者为Anatoly Vorobey和Brad Fitzpatrick。用于提升LiveJournal.com访问速度的。LJ每秒动态页面访问量几千次，用户700万。Memcached将数据库负载大幅度降低，更好的分配资源，更快速访问。<br /><br /><span style="text-align: center; widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 22px; font-family: Arial, Helvetica, simsun, u5b8bu4f53; color: rgb(95,94,94); font-size: 14px" class="Apple-style-span"><strong style="line-height: 22px">Memcached适合什么场合<br /><br style="line-height: 22px" /></strong></span><span style="text-align: left; line-height: 22px; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px" class="Apple-style-span">Memcached在很多时候都是作为数据库前端cache使用的。因为它比数据库少了很多SQL解析、磁盘操作等开销，而且它是使用内存来管理数据的， 所以它可以提供比直接读取数据库更好的性能，在大型系统中，访问同样的数据是很频繁的，memcached可以大大降低数据库压力，使系统执行效率提升。 另外，memcached也经常作为服务器之间数据共享的存储媒介，例如在SSO系统中保存系统单点登陆状态的数据就可以保存在memcached中，被 多个应用共享。<br style="line-height: 22px" /><br style="line-height: 22px" /></span><span style="text-align: left; line-height: 22px; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px" class="Apple-style-span">需要注意的是，memcached使用内存管理数据，所以它是易失的，当服务器重启，或者memcached进程中止，数据便会丢失，所以 memcached不能用来持久保存数据。很多人的错误理解，memcached的性能非常好，好到了内存和硬盘的对比程度，其实memcached使用 内存并不会得到成百上千的读写速度提高，它的实际瓶颈在于网络连接，它和使用磁盘的数据库系统相比，好处在于它本身非常&#8220;轻&#8221;，因为没有过多的开销和直接 的读写方式，它可以轻松应付非常大的数据交换量，所以经常会出现两条千兆网络带宽都满负荷了，memcached进程本身并不占用多少CPU资源的情况。<span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="font-family: 'Comic Sans MS', 宋体, Arial; color: rgb(51,51,51); font-size: 12px" class="Apple-style-span"></span></span><br /><br /></span><span style="text-align: left; line-height: 22px; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px" class="Apple-style-span"><br /></span><span style="text-align: left; line-height: 22px; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px" class="Apple-style-span"><br /><br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 21px; font-family: verdana, sans-serif; font-size: 14px" class="Apple-style-span">Memcached的使用（windows下使用）<br /></span></span>1.到<a href="http://code.jellycan.com/memcached/">http://code.jellycan.com/memcached/</a>下载最新版的<span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 21px; font-family: verdana, sans-serif; font-size: 14px" class="Apple-style-span">Memcached</span></span><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 20px; font-family: Verdana, Simsun, sans-serif; color: rgb(51,51,51); font-size: 13px" class="Apple-style-span">2. 在终端（也即cmd命令界面）下输入 &#8216;c:\memcached\memcached.exe -d install&#8217; 安装<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />3. 再输入： &#8216;c:\memcached\memcached.exe -d start&#8217; 启动。NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动。这样服务器端已经安装完毕了。<br /></span></span><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 20px; font-family: Verdana, Simsun, sans-serif; color: rgb(51,51,51); font-size: 13px" class="Apple-style-span"><strong style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">memcached的基本设置</strong>：</span></span><br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 20px; font-family: Verdana, Simsun, sans-serif; color: rgb(51,51,51); font-size: 13px" class="Apple-style-span">-p 监听的端口<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-l 连接的IP地址, 默认是本机<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-d start 启动memcached服务<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-d restart 重起memcached服务<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-d stop|shutdown 关闭正在运行的memcached服务<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-d install 安装memcached服务<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-d uninstall 卸载memcached服务<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-u 以的身份运行 (仅在以root运行的时候有效)<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-m 最大内存使用，单位MB。默认64MB<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-M 内存耗尽时返回错误，而不是删除项<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-c 最大同时连接数，默认是1024<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-f 块大小增长因子，默认是1.25<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-n 最小分配空间，key+value+flags默认是48<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />-h 显示帮助</span></span><br /><br /><br />客户端使用：<br />memcache的各种客户端如下：<br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 25px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 14px" class="Apple-style-span">http://code.google.com/p/memcached/wiki/Clients<br /><br /><span style="text-align: left; line-height: 22px; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px" class="Apple-style-span">windows下c++可以使用：<br /><a href="http://code.jellycan.com/memcacheclient/">http://code.jellycan.com/memcacheclient/</a><br /><br />可以简单的操作添加，获取，删除，跟新键值等操作。</span><br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="font-family: 'Comic Sans MS', 宋体, Arial; color: rgb(51,51,51); font-size: 14pt" class="Apple-style-span"><strong>MemCac</strong></span><span style="font-family: 'Comic Sans MS', 宋体, Arial; color: rgb(51,51,51); font-size: 12px" class="Apple-style-span"><strong>he接口介绍</strong></span></span><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="font-family: 'Comic Sans MS', 宋体, Arial; color: rgb(51,51,51); font-size: 12px" class="Apple-style-span">&nbsp; 
<p><span style="font-size: 12pt">Memcache客户端包含两组接口，一组是面向过程的接口，一组是面向对象的接口，具体可以参考PHP手册 &#8220;LXXV. Memcache Functions&#8221; 这章。</span></p>
<p><span style="font-size: 12pt">Memcache面向对象的常用接口包括：</span><br /><span style="font-size: 12pt">Memcache::connect &#8212; 打开一个到Memcache的连接</span><br /><span style="font-size: 12pt">Memcache::pconnect &#8212; 打开一个到Memcache的长连接</span><br /><span style="font-size: 12pt">Memcache::close &#8212; 关闭一个Memcache的连接</span><br /><span style="font-size: 12pt">Memcache::set &#8212; 保存数据到Memcache</span><span style="font-size: 12pt">服务器</span><span style="font-size: 12pt">上</span><br /><span style="font-size: 12pt">Memcache::get &#8212; 提取一个保存在Memcache服务器上的数据</span><br /><span style="font-size: 12pt">Memcache::replace &#8212; 替换一个已经存在Memcache服务器上的项目（功能类似Memcache::set）</span><br /><span style="font-size: 12pt">Memcache::delete &#8212; 从Memcache服务器上删除一个保存的项目</span><br /><span style="font-size: 12pt">Memcache::flush &#8212; 刷新所有Memcache服务器上保存的项目（类似于删除所有的保存的项目）</span></p>
<p><span style="font-size: 12pt">Memcache::getStats &#8212; 获取当前Memcache服务器运行的状态</span><br /><br /></p></span></span><br /><br /></span></span></span></span></span></span><img src ="http://www.cppblog.com/AutomateProgram/aggbug/149762.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2011-06-29 17:20 <a href="http://www.cppblog.com/AutomateProgram/archive/2011/06/29/149762.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sqlite3: 一个SQLite数据库的命令行接口</title><link>http://www.cppblog.com/AutomateProgram/archive/2011/06/16/148819.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 16 Jun 2011 15:15:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2011/06/16/148819.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/148819.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2011/06/16/148819.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/148819.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/148819.html</trackback:ping><description><![CDATA[原文地址：<a href="http://blogold.chinaunix.net/u3/90025/showart_1764687.html">http://blogold.chinaunix.net/u3/90025/showart_1764687.html</a><br /><br />原文地址：<a style="color: rgb(64,115,171); text-decoration: none" href="http://www.sqlite.org/sqlite.html">http://www.sqlite.org/sqlite.html</a> 
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp;&nbsp; SQLite库包含一个名字叫做<strong>sqlite3</strong>的命令行,它可以让用户手工输入并执行面向SQLite数据库的SQL命令。本文档提供一个样使用sqlite3的简要说明。</p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><strong><font size="3">开始</font></strong></p>
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 启动<strong>sqlite3</strong>程序，仅仅需要敲入带有SQLite数据库名字的"<strong>sqlite3</strong>"命令即可。如果文件不存在，则创建一个新的（数据库）文件。然后<strong>sqlite3</strong>程序将提示你输入SQL。敲入SQL语句（以分号&#8220;；&#8221;结束），敲回车键之后，SQL语句就会执行。</p>
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 例如，创建一个包含一个表"tb11"名字为"ex1"的SQLite数据库，你可以这样做：</p>
<p style="font-family: 宋体, Arial; font-size: 9pt">$<strong>sqlite3 ex1</strong><br />SQLite version 3.3.17<br />Enter ".help" for instructions<br />sqlite&gt;<span class="Apple-converted-space">&nbsp;</span><strong>create table tbl1(one varchar(10), two smallint);</strong><br />sqlite&gt;<span class="Apple-converted-space">&nbsp;</span><strong>insert into tbl1 values('hello!', 10);<br /></strong>sqlite&gt;<span class="Apple-converted-space">&nbsp;</span><strong>insert into tbl1 values('goodbye', 20);<br /></strong>sqlite&gt;<span class="Apple-converted-space">&nbsp;</span><strong>select * from tbl1;<br /></strong>hello!|10<br />goodbye|20<br />sqlite&gt;</p>
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 你可以通过敲你所用系统的文件结束符（通常是Ctrl + D）或者中断字符（通常是Ctrl + C）。来终止sqlite3程序。确定你在每个SQL语句结束敲入分号！sqlite3程序通过查找分号来决定一个SQL语句的结束。如果你省略分号，sqlite3将给你一个连续的命令提示符并等你给当前的SQL命令添加更多的文字。这个特点让你输入多行的多个SQL语句，例如：</p>
<p style="font-family: 宋体, Arial; font-size: 9pt">sqlite&gt;<span class="Apple-converted-space">&nbsp;</span><strong>create table tbl2(<br /></strong>&nbsp;&nbsp; ...&gt;<strong><span class="Apple-converted-space">&nbsp;</span>f1 varchar(30) primary key,<br /></strong>&nbsp;&nbsp; ...&gt;<span class="Apple-converted-space">&nbsp;</span><strong>f2 text,<br /></strong>&nbsp;&nbsp; ...&gt;<span class="Apple-converted-space">&nbsp;</span><strong>f3 real<br /></strong>&nbsp;&nbsp; ...&gt;<span class="Apple-converted-space">&nbsp;</span><strong>);<br /></strong>sqlite&gt;</p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><strong><font size="3">题外话：查询SQLITE_MASTER表</font></strong></p>
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp;&nbsp; SQLite数据库的框架被保存在一个名叫"sqlite_master"的特殊的表中。你可以像查询其它表一样通过执行&#8220;SELECT&#8221;查询这个特殊的表。例如：</p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><br /><font face="NSimsun">$&nbsp;<strong>sqlite3&nbsp;ex1</strong><br />SQlite&nbsp;vresion&nbsp;3.3.10<br />Enter&nbsp;".help"&nbsp;for&nbsp;instructions<br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;sqlite_master;</strong><br />&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;=&nbsp;table<br />&nbsp;&nbsp;&nbsp;&nbsp;name&nbsp;=&nbsp;tbl1<br />tbl_name&nbsp;=&nbsp;tbl1<br />rootpage&nbsp;=&nbsp;3<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql&nbsp;=&nbsp;create&nbsp;table&nbsp;tbl1(one&nbsp;varchar(10),&nbsp;two&nbsp;smallint)<br />sqlite&gt;</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp;&nbsp; 但你不能在sqlite_master表中执行诸如DROP TABLE, UPDATE, INSERT 或者DELETE命令。sqlite_master表在你创建、删除和索引数据库时自动更新这个表。你不能手工更改sqlite_master表。</p>
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp;&nbsp; TEMPORARY表的结构没有存储在"sqlite_master"表中，由于TEMPORARY表对应用是不可见的，而不是应用程序创建这个表。TEMPORARY表结构被存储在另外一个名叫"sqlite_temp_master"的特定的表中。"sqlite_temp_master"表是临时表自身。</p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><strong>sqlite3的特殊命令</strong></p>
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp; 大多数候，sqlite3读入输入行，并把它们传递到SQLite库中去运行。但是如果输入行以一个点（&#8220;.&#8221;）开始，那么这行将被sqlite3程序自己截取并解释。这些&#8220;点命令&#8221;通常被用来改变查询输出的格式，或者执行鞭个预封包（预定义prepackaged）的查询语句。</p>
<p style="font-family: 宋体, Arial; font-size: 9pt">你可以在任何时候输入&#8220;.help&#8221;，列出可用的点命令。例如</p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.help</strong><br />.bail&nbsp;ON|OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stop&nbsp;after&nbsp;hitting&nbsp;an&nbsp;error.&nbsp;&nbsp;Default&nbsp;OFF<br />.databases&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;names&nbsp;and&nbsp;files&nbsp;of&nbsp;attached&nbsp;databases<br />.dump&nbsp;?TABLE?&nbsp;...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dump&nbsp;the&nbsp;database&nbsp;in&nbsp;an&nbsp;SQL&nbsp;text&nbsp;format<br />.echo&nbsp;ON|OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Turn&nbsp;command&nbsp;echo&nbsp;on&nbsp;or&nbsp;off<br />.exit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit&nbsp;this&nbsp;program<br />.explain&nbsp;ON|OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Turn&nbsp;output&nbsp;mode&nbsp;suitable&nbsp;for&nbsp;EXPLAIN&nbsp;on&nbsp;or&nbsp;off.<br />.header(s)&nbsp;ON|OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Turn&nbsp;display&nbsp;of&nbsp;headers&nbsp;on&nbsp;or&nbsp;off<br />.help&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show&nbsp;this&nbsp;message<br />.import&nbsp;FILE&nbsp;TABLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Import&nbsp;data&nbsp;from&nbsp;FILE&nbsp;into&nbsp;TABLE<br />.indices&nbsp;TABLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show&nbsp;names&nbsp;of&nbsp;all&nbsp;indices&nbsp;on&nbsp;TABLE<br />.load&nbsp;FILE&nbsp;?ENTRY?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Load&nbsp;an&nbsp;extension&nbsp;library<br />.mode&nbsp;MODE&nbsp;?TABLE?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set&nbsp;output&nbsp;mode&nbsp;where&nbsp;MODE&nbsp;is&nbsp;one&nbsp;of:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;csv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Comma-separated&nbsp;values<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;column&nbsp;&nbsp;&nbsp;Left-aligned&nbsp;columns.&nbsp;&nbsp;(See&nbsp;.width)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HTML&nbsp;&lt;table&gt;&nbsp;code<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;insert&nbsp;&nbsp;&nbsp;SQL&nbsp;insert&nbsp;statements&nbsp;for&nbsp;TABLE<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;One&nbsp;value&nbsp;per&nbsp;line<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Values&nbsp;delimited&nbsp;by&nbsp;.separator&nbsp;string<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tabs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tab-separated&nbsp;values<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tcl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TCL&nbsp;list&nbsp;elements<br />.nullvalue&nbsp;STRING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print&nbsp;STRING&nbsp;in&nbsp;place&nbsp;of&nbsp;NULL&nbsp;values<br />.output&nbsp;FILENAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Send&nbsp;output&nbsp;to&nbsp;FILENAME<br />.output&nbsp;stdout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Send&nbsp;output&nbsp;to&nbsp;the&nbsp;screen<br />.prompt&nbsp;MAIN&nbsp;CONTINUE&nbsp;&nbsp;Replace&nbsp;the&nbsp;standard&nbsp;prompts<br />.quit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit&nbsp;this&nbsp;program<br />.read&nbsp;FILENAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Execute&nbsp;SQL&nbsp;in&nbsp;FILENAME<br />.schema&nbsp;?TABLE?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show&nbsp;the&nbsp;CREATE&nbsp;statements<br />.separator&nbsp;STRING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Change&nbsp;separator&nbsp;used&nbsp;by&nbsp;output&nbsp;mode&nbsp;and&nbsp;.import<br />.show&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show&nbsp;the&nbsp;current&nbsp;values&nbsp;for&nbsp;various&nbsp;settings<br />.tables&nbsp;?PATTERN?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;names&nbsp;of&nbsp;tables&nbsp;matching&nbsp;a&nbsp;LIKE&nbsp;pattern<br />.timeout&nbsp;MS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Try&nbsp;opening&nbsp;locked&nbsp;tables&nbsp;for&nbsp;MS&nbsp;milliseconds<br />.width&nbsp;NUM&nbsp;NUM&nbsp;...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set&nbsp;column&nbsp;widths&nbsp;for&nbsp;"column"&nbsp;mode<br />sqlite&gt;</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font size="4" face="新宋体"><strong>改变输出格式</strong></font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; sqlite3程序可以以八种不同的格式显示一个查询的结果："csv", "列", "html", "插入", "行", "制表"和"tcl"。你可以用".mode"点命令在这些输出格式之间切换。</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 默认的输出格式是&#8220;列表&#8221;。在列表模式下，每条查询结果记录被写在一行中并且每列之间以一个字符串分割符隔开。默认的分隔符是一个管道符号（&#8220;|&#8221;）。列表符号在当你输出查询结果到另外一个符加处理的程序（如AWK）中去是尤为有用。</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.mode&nbsp;list</strong><br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;tbl1;</strong><br />hello|10<br />goodbye|20<br />sqlite&gt;</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 你可以用&#8220;.separator&#8221;点命令来改变分界符。例如，为了把分割符改为一个逗号和一个空格，你可以这样做：</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.separator&nbsp;",&nbsp;"</strong><br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;tbl1;</strong><br />hello,&nbsp;10<br />goodbye,&nbsp;20<br />sqlite&gt;</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 在&#8220;line"模式下，每一个位于条记录中的列在它自己那行显示。每行由列名、一个等号和列数据组成。下一条记录以一个空行隔开。这是一个行模式输出的例子：</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.mode&nbsp;line</strong><br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;tbl1;</strong><br />one&nbsp;=&nbsp;hello<br />two&nbsp;=&nbsp;10<br /><br />one&nbsp;=&nbsp;goodbye<br />two&nbsp;=&nbsp;20<br />sqlite&gt;</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 在列模式下，每条记录在一个单独的行中以数据列对齐的方式显示。列如：</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.mode&nbsp;column</strong><br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;tbl1;</strong><br />one&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;two&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />----------&nbsp;&nbsp;----------<br />hello&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />goodbye&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />sqlite&gt;</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在默认的情况下，每列至少10个字符宽。太宽的数据将被截取。你可以用&#8220;.width&#8221;命令来调整列宽。如下所示：</p>
<blockquote style="margin-right: 0px" dir="ltr">
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.width&nbsp;12&nbsp;6</strong><br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;tbl1;</strong><br />one&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;two&nbsp;&nbsp;&nbsp;<br />------------&nbsp;&nbsp;------<br />hello&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;<br />goodbye&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;&nbsp;<br />sqlite&gt;</font></p></blockquote>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp;&nbsp;上面例子中".width"命令设置第一列宽为12第二列宽为6。其它的列宽不变。你可以指定与你查询结果需要的列数一样多的&#8220;.width&#8221;参数。</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 如果你指定一列宽为0，那么这个列宽将自动以下面三个数字中的最大值做为列宽：10、表头宽度和最宽的数据列的宽度。这可以让列自动调整宽度。每列的默认设置为自动调整的0值。</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 出现在输出开头两行的列标示可以用".header"点命令关闭。在上面的例子中，列标示是打开的。可以用下面的方法关闭列标示：</font></p>
<blockquote style="margin-right: 0px" dir="ltr">
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.header&nbsp;off</strong><br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;tbl1;</strong><br />hello&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;<br />goodbye&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;&nbsp;<br />sqlite&gt;</font></p></blockquote>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 另外一个有用的输出模式是"insert"。在插入模式下，被子格式化为看起来像SQL INSERT语句的样式。你可以用插入模式来产生文件（便于）以后用于不同数据库的输入。</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 当指定插入模式时，你必须给定一个特定参数就是要插入的表名。例如：</font></p>
<blockquote style="margin-right: 0px" dir="ltr">
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.mode&nbsp;insert&nbsp;new_table</strong><br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;tbl1;</strong><br />INSERT&nbsp;INTO&nbsp;'new_table'&nbsp;VALUES('hello',10);<br />INSERT&nbsp;INTO&nbsp;'new_table'&nbsp;VALUES('goodbye',20);<br />sqlite&gt;</font></p></blockquote>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 最新的输出格式是&#8220;html&#8221;。在这种模式下，sqlite3把查询的结果写做XHTML表。开始的&lt;TABLE&gt;和结束的&lt;/TABLE&gt;（标记）没有写出，但有&lt;TR&gt;、&lt;TH&gt;和&lt;TD&gt;等分界符。html输出对CGI来说是相当有用地。</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font size="4" face="新宋体"><strong>把结果写到文件中</strong></font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="新宋体">&nbsp;&nbsp;&nbsp; 默认情况下，sqlte3把结送到标准输出。你可以用&#8220;.output&#8221;命令改变它。只须把输出文件名做为.output命令的输出参数然后所有后续查询结果将被写到那个文件中。用&#8220;.output stdout&#8221;再一次改为标准输出。例如：</font></p>
<blockquote style="margin-right: 0px" dir="ltr">
<p style="font-family: 宋体, Arial; font-size: 9pt"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.mode&nbsp;list</strong><br />sqlite&gt;&nbsp;<strong>.separator&nbsp;|</strong><br />sqlite&gt;&nbsp;<strong>.output&nbsp;test_file_1.txt</strong><br />sqlite&gt;&nbsp;<strong>select&nbsp;*&nbsp;from&nbsp;tbl1;</strong><br />sqlite&gt;&nbsp;<strong>.exit</strong><br />$&nbsp;<strong>cat&nbsp;test_file_1.txt</strong><br />hello|10<br />goodbye|20<br />$</font></p></blockquote>
<p style="font-family: 宋体, Arial; font-size: 9pt" dir="ltr"><font size="4" face="新宋体"><strong>查询数据库结构</strong></font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt" dir="ltr"><font face="新宋体">&nbsp;&nbsp;&nbsp;&nbsp;sqlite3程序提供几个有用的用于查询数据库结构的快捷命令。这些不是不可以用别的方式来实现。这些命令仅仅是一个快捷方式而已。</font></p>
<p style="font-family: 宋体, Arial; font-size: 9pt" dir="ltr"><font face="新宋体">&nbsp;&nbsp;&nbsp; 例如，为了查看数据库的表列表，你可以敲入&#8220;.tables&#8221;。</font></p>
<blockquote style="margin-right: 0px" dir="ltr">
<p style="font-family: 宋体, Arial; font-size: 9pt" dir="ltr"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.tables</strong><br />tbl1<br />tbl2<br />sqlite&gt;</font></p></blockquote>
<p style="font-family: 宋体, Arial; font-size: 9pt" dir="ltr"><font face="新宋体">&nbsp;&nbsp;&nbsp; &#8220;.tables&#8221;命令相似于设置列表模式然后执行接下来的查询：</font></p>
<blockquote style="margin-right: 0px" dir="ltr"><font face="新宋体"><pre>SELECT name FROM sqlite_master 
WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'
UNION ALL 
SELECT name FROM sqlite_temp_master 
WHERE type IN ('table','view') 
ORDER BY 1</pre></font></blockquote><font face="新宋体"><pre dir="ltr">事实上，你可以查看sqlite3的源代码（可以在源文件树的src/shell.c中），你可找到上面的具体的查询。</pre><pre dir="ltr">&#8220;.indices&#8221;命令作用类似的方式是列出特定表的所有的索引。&#8220;.indics&#8221;命令须一个参数即所要索引表的表名。最后，但不是至少，是&#8220;.schema&#8221;命令。不带任何参数，&#8220;.schema&#8221;命令显示原始的用于创建当前数据库的CREATE TABLE和CREATE INDEX语句。如果你给".schema"命令一个表名，它显示原始的创建该表和它所有索引的CREATE语句。我们可以：</pre></font>
<blockquote style="margin-right: 0px" dir="ltr"><pre dir="ltr"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.schema</strong><br />create&nbsp;table&nbsp;tbl1(one&nbsp;varchar(10),&nbsp;two&nbsp;smallint)<br />CREATE&nbsp;TABLE&nbsp;tbl2&nbsp;(<br />&nbsp;&nbsp;f1&nbsp;varchar(30)&nbsp;primary&nbsp;key,<br />&nbsp;&nbsp;f2&nbsp;text,<br />&nbsp;&nbsp;f3&nbsp;real<br />)<br />sqlite&gt;&nbsp;<strong>.schema&nbsp;tbl2</strong><br />CREATE&nbsp;TABLE&nbsp;tbl2&nbsp;(<br />&nbsp;&nbsp;f1&nbsp;varchar(30)&nbsp;primary&nbsp;key,<br />&nbsp;&nbsp;f2&nbsp;text,<br />&nbsp;&nbsp;f3&nbsp;real<br />)<br />sqlite&gt;</font></pre></blockquote><pre dir="ltr"><font face="新宋体">    ".schema"命令可以用设置列表然后执行以下查询来实现：</font></pre>
<blockquote style="margin-right: 0px" dir="ltr">
<div style="margin-right: 0px" dir="ltr">
<p style="font-family: 宋体, Arial; font-size: 9pt; margin-right: 0px" dir="ltr">&nbsp;</p><pre dir="ltr"><font face="新宋体"><pre>SELECT sql FROM 
   (SELECT * FROM sqlite_master UNION ALL
    SELECT * FROM sqlite_temp_master)
WHERE type!='meta'
ORDER BY tbl_name, type DESC, name</pre>
</font></pre><font face="新宋体">
<p style="font-family: 宋体, Arial; font-size: 9pt">&nbsp;</p></font></div></blockquote><font face="新宋体"><pre dir="ltr">或者，如果你给".schema"命令一个参数，由于你只想得到一个表的结构，查询可以是这样：</pre>
<blockquote style="margin-right: 0px" dir="ltr"><pre dir="ltr">SELECT sql FROM
   (SELECT * FROM sqlite_master UNION ALL
    SELECT * FROM sqlite_temp_master)
WHERE type!='meta' AND sql NOT NULL AND name NOT LIKE 'sqlite_%'
ORDER BY substr(type,2,1), name</pre></blockquote><pre dir="ltr">你可以担供一个参数给.schema命令。如果这橛，查询可以是这样的：</pre>
<blockquote style="margin-right: 0px" dir="ltr"><pre dir="ltr"><pre>SELECT sql FROM
   (SELECT * FROM sqlite_master UNION ALL
    SELECT * FROM sqlite_temp_master)
WHERE tbl_name LIKE '%s'
  AND type!='meta' AND sql NOT NULL AND name NOT LIKE 'sqlite_%'
ORDER BY substr(type,2,1), name</pre>
</pre></blockquote><pre dir="ltr">在查询中&#8220;%S&#8220;为你的参数所取代。这使你可以询数据库结构的某个子集。</pre>
<blockquote style="margin-right: 0px" dir="ltr"><pre dir="ltr"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.schema&nbsp;%abc%</strong></font></pre></blockquote><pre dir="ltr"><font face="新宋体"><strong>    </strong>与这些一起，&#8220;.table&#8221;命令也接受一个模式作为他的参数。如果你给&#8220;.table&#8221;一个参数，&#8220;%&#8221;将被前后扩展并且一个LIKE子句被附加到查询上。这让你可以列出只与特定模式相匹配的的表。</font></pre><pre dir="ltr"><font face="新宋体">    &#8220;.datebasae&#8221;命令显示所有当前连接打开的数据库的一个列表。将允许一次到少两个。第一个是&#8220;main&#8221;，最初打开的那个数据库。第二个是"temp"，用于临时表的数据库。对于用ATTACH语句附加的数据也许有附加数据库列表。输出的第一列与之相联的数据库名，第二列是外部文件名。</font></pre>
<blockquote style="margin-right: 0px" dir="ltr"><pre dir="ltr"><font face="NSimsun">sqlite&gt;&nbsp;<strong>.databases</strong></font></pre></blockquote><pre dir="ltr"><font face="新宋体"><strong>    <font size="4">将整个数据库转换为ASCII文本文件</font></strong></font></pre><pre dir="ltr"><font size="3" face="新宋体"><strong>    </strong><font size="2">".dump"命令成一个单一的ASCII文本文件。这个文件可以被用作管道传递给sqlite3命令来转换回数据库。</font></font></pre><pre dir="ltr"><font size="2" face="新宋体">    一个最好的制作一个数据库档案拷贝的命令是：</font></pre>
<blockquote style="margin-right: 0px" dir="ltr"><pre dir="ltr"><font size="2" face="NSimsun">$&nbsp;<strong>echo&nbsp;'.dump'&nbsp;|&nbsp;sqlite3&nbsp;ex1&nbsp;|&nbsp;gzip&nbsp;-c&nbsp;&gt;ex1.dump.gz</strong> </font></pre></blockquote><pre dir="ltr"><font size="3" face="新宋体">    <font size="2">它产生一个一个名为<strong>ex1.dump.gz</strong>的文件，它包含了你以后或在其它机器上重构数据库的所有的信息。要重构数据库，只须敲入：</font></font></pre>
<blockquote style="margin-right: 0px" dir="ltr"><pre dir="ltr"><font size="2" face="NSimsun">$&nbsp;<strong>zcat&nbsp;ex1.dump.gz&nbsp;|&nbsp;sqlite3&nbsp;ex2</strong> </font></pre></blockquote><pre dir="ltr"><font size="2" face="新宋体">    这个文本格式是纯粹的SQL语句所以你可以用.dump命令来导出一个SQLite数据库到另一个常用的SQL数据库引擎。比如：</font></pre>
<blockquote style="margin-right: 0px" dir="ltr"><pre dir="ltr"><font size="2" face="NSimsun">$&nbsp;<strong>createdb&nbsp;ex2</strong><br />$&nbsp;<strong>sqlite3&nbsp;ex1&nbsp;.dump&nbsp;|&nbsp;psql&nbsp;ex2</strong> </font></pre></blockquote><pre dir="ltr"><strong><font size="4">其它的点命令</font></strong></pre><pre dir="ltr">".explain"命令可以被用来设置输出格式为&#8220;column&#8221;&nbsp;并设置列宽为EXPLAIN命令看起来比较合理的宽度。EXPLAIN命令是SQLite特有的SQL扩展，它是对调试有用。如果任何常规的SQL被EXPLAIN执行，那么SQL命令被分解并分析但并不执行。取而代之的是，虚拟机指令序列将被用于执行SQL命令并返回一个类似的查询结果。如：</pre><pre dir="ltr"><blockquote><p style="font-family: 宋体, Arial; font-size: 9pt"><tt><font face="NSimsun">sqlite&gt;&nbsp;<strong>.explain</strong><br />sqlite&gt;&nbsp;<strong>explain&nbsp;delete&nbsp;from&nbsp;tbl1&nbsp;where&nbsp;two&lt;20;</strong><br />addr&nbsp;&nbsp;opcode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />----&nbsp;&nbsp;------------&nbsp;&nbsp;-----&nbsp;&nbsp;-----&nbsp;&nbsp;-------------------------------------&nbsp;&nbsp;&nbsp;<br />0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListOpen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Open&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tbl1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Next&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Field&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Integer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ge&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Key&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListWrite&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Goto&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Noop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />10&nbsp;&nbsp;&nbsp;&nbsp;ListRewind&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />11&nbsp;&nbsp;&nbsp;&nbsp;ListRead&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />12&nbsp;&nbsp;&nbsp;&nbsp;Delete&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />13&nbsp;&nbsp;&nbsp;&nbsp;Goto&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />14&nbsp;&nbsp;&nbsp;&nbsp;ListClose&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</font></tt></p></blockquote></pre><pre><tt><font face="新宋体">    &#8220;.timeout&#8221;命令设置sqlite3等待一个试图存储文件锁定请除直到错误返回的总时间。默认的超时值是0因此如果任何需要的数据库表或序列列被锁定时它将立即返回一个错误。</font></tt></pre><pre><tt><font face="新宋体">    最后，我们提到&#8220;.exit&#8221;命令它交导致sqlite3退出。</font></tt></pre><pre><tt><font size="4" face="新宋体"><strong>在命令和脚本中使用sqlite3</strong></font></tt></pre><pre><tt><font face="新宋体">    一个在脚本命令中使用sqlite3的方式是用&#8220;echo&#8221;或&#8220;cat&#8221;来产生一个命令序列在一个文件中，然后当从一个产生的命令行中重定向输入时调用sqlite3。它有用并且适应许多环境。但作为一附加的便利是，sqlite3允许一个单一的SQL语句在命令行中作为数据库名后的第二个参数输入。当sqlite3程序带着两个参数启动时，第二个参数被传递给SQLite库处理，查询以列表模式打印到标准输出，然后程序退出。这个机制被设计用于让sqlite3容易于用于连接诸如"AWK"的程序。例如：</font></tt></pre>
<blockquote style="margin-right: 0px" dir="ltr"><pre><tt><font face="NSimsun">$&nbsp;<strong>sqlite3&nbsp;ex1&nbsp;'select&nbsp;*&nbsp;from&nbsp;tbl1'&nbsp;|</strong><br />&gt;&nbsp;<strong>&nbsp;awk&nbsp;'{printf&nbsp;"&lt;tr&gt;&lt;td&gt;%s&lt;td&gt;%s\n",$1,$2&nbsp;}'</strong><br />&lt;tr&gt;&lt;td&gt;hello&lt;td&gt;10<br />&lt;tr&gt;&lt;td&gt;goodbye&lt;td&gt;20<br />$ </font></tt></pre></blockquote><pre dir="ltr"><tt><font size="4" face="新宋体"><strong>结束命令行命令</strong></font></tt></pre><pre dir="ltr"><tt><font face="新宋体">    SQLite命令通常以一个分号结束。在一个命令行中你也可以用&#8220;GO&#8221;单词（大小写敏感）或者一个&#8220;/&#8221;斜线在它所在好行结束一个命令。这常被SQL Server和Oracle使用。这些将不在sqlite3_exec()中有用，因为命令行在传递它们到函数之前把这些翻译为分号。</font></tt></pre><pre dir="ltr"><tt><font size="4" face="新宋体"><strong>从源文件中编译sqlite3</strong></font></tt></pre><pre dir="ltr"><tt><font face="新宋体">    sqlite3程序当你编译SQLite库时自动被建立。只须取得一个源文件树的拷贝，运行&#8220;configure"然后"make"即可。<br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: 14px/21px 宋体; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(42,42,42); word-spacing: 0px; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0" class="Apple-style-span"><p>SQLite3的Shell(1)</p><p>sqlite3.exe是SQLite访问数据库的一个工具，使用命令行的形式。<br />Shell的命令分为两种，第一是Shell本身的命令，以点开头。第二是用来管理当前数据库的SQL命令，以分号结束。<br />其中Shell本身的命令分以下几种：控制数据的显示模式；设置Shell读取和显示数据的方式；其他系统控制命令</p><p>常用的显示模式控制命令：<br />.header ON|OFF：设置是否显示数据表格的列名<br />.indices TABLE：显示表格的所有列名<br />.mode MODE：设置数据表格的显示模式。默认是list，用.separator命令设置的字符串分隔字符(默认是|)。我们比较习惯的是column格式<br />.nullvalue STRING：当数据为空时，用STRING来填充。默认是空字符串，也就是什么也不显示。<br />.tables PATTERN：使用PATTERN模式来显示表格<br />.width NUM NUM...：设置当以column模式显示时，数据显示的宽度</p><p>.output FILENAME|stdout：设置数据输出的形式：文件或屏幕的标准输出。<br />.read FILENAME：从文件读取SQL语句</p><p><br />其他系统控制命令：<br />.databases：显示目前已经匹配的数据库名称<br />.table：显示当前数据库中的所有表<br />.help：显示shell的帮助信息<br />.show：显示shell目前的设置参数<br />.quit 和.exit：退出shell<br /></p><p>参考：<a style="color: rgb(94,72,48)" href="http://www.sqlite.org/sqlite.html">http://www.sqlite.org/sqlite.html</a></p></span></font></tt></pre></font><img src ="http://www.cppblog.com/AutomateProgram/aggbug/148819.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2011-06-16 23:15 <a href="http://www.cppblog.com/AutomateProgram/archive/2011/06/16/148819.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用vs2005单步调试sqlite3.6.23(vs2005 编译sqlite 并使用shell)</title><link>http://www.cppblog.com/AutomateProgram/archive/2011/06/16/148817.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 16 Jun 2011 15:07:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2011/06/16/148817.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/148817.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2011/06/16/148817.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/148817.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/148817.html</trackback:ping><description><![CDATA[<p><font style="background-color: #cce8cf">原文地址：<a href="http://blog.csdn.net/spche/archive/2010/06/10/5661580.aspx">http://blog.csdn.net/spche/archive/2010/06/10/5661580.aspx</a><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 21px; font-family: verdana, sans-serif; font-size: 14px" class="Apple-style-span"> </p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">网上大多数的使用vs2005编译sqlite是编译成为dll，我的目的是为了分析sqlite，所以还是编译成一个可执行程序方便单步调试</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">1.创建一个空的Win32 Console Application工程，</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">2.sqlite3.6.23的所有源码均加入工程，除去以下几个</p><li style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">mutex_os2.c</li><li style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">mutex_unix.c</li><li style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">os_os2.c</li><li style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">os_unix.c</li><li style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">tclsqlite.c 
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">shell.c 可去可不去，不去的话，可生成执行SQL的输入控制吧，方便调试；去掉的话，需要自已编写一个测试的C文件，</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">3.选择合适的RuntimeLibrary，默认为多线程模式。位置：Project-&gt;Properties-&gt;Configuration Properties-&gt;C/C++-&gt;Code Generation-&gt;Runtime Library，这个没有改，就是默认多线程的</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">4.将编译模式改为c模式（TC）。位置：Project-&gt;Properties-&gt;Configuration Properties-&gt;C/C++-&gt;Advanced-&gt;Compile As。默认的是C++的，这个需要改</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">5.如果想要取得不必要的警告信息，则作如下处理：</p>
<div>- 在预处理定义处加 NO_TCL _CRT_SECURE_NO_WARNINGS SQLITE_ENABLE_FTS3 SQLITE_ENABLE_FTS3_PARENTHESIS<span class="Apple-converted-space">&nbsp;</span><span style="font-family: Verdana">SQLITE_ENABLE_RTREE</span><br />位置: Project-&gt;Properties-&gt;Configuration Properties-&gt;C/C++-&gt;Preprocessor-&gt;Preprocessor Definitions<br />
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">- disable 制定的警告信息(Project-&gt;Properties-&gt;C/C++-&gt;Advanced-&gt;Disable Specific Warnings): 4267;4244;4018;4311;4996;4312;4311</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">6.将fts3_tokenizer.c中27行的</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img id="Codehighlighter1_0_128_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_128_Open_Text.style.display='none'; Codehighlighter1_0_128_Closed_Image.style.display='inline'; Codehighlighter1_0_128_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_128_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_128_Closed_Text.style.display='none'; Codehighlighter1_0_128_Open_Image.style.display='inline'; Codehighlighter1_0_128_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_128_Closed_Text">/**/</span><span id="Codehighlighter1_0_128_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />#include&nbsp;"sqlite3ext.h"<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />#ifndef&nbsp;SQLITE_CORE<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />//SQLITE_EXTENSION_INIT1<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />extern&nbsp;const&nbsp;sqlite3_api_routines&nbsp;*sqlite3_api;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />#endif<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" /></span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">fts3_tokenizer.h</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px"><br /><br /></p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">把rtree.c的2877行</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">/*<br />#if !SQLITE_CORE<br />int sqlite3_extension_init(<br />sqlite3 *db,<br />char **pzErrMsg,<br />const sqlite3_api_routines *pApi<br />){<br />SQLITE_EXTENSION_INIT2(pApi)<br />return sqlite3RtreeInit(db);<br />}<br />#endif<br />*/</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">56行改为</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">/*<br />#ifndef SQLITE_CORE<br />#include "sqlite3ext.h"<br />SQLITE_EXTENSION_INIT1<br />#else<br />#include "sqlite3.h"<br />#endif<br />*/<br />#include "rtree.h"</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">外部引用有问题，估计功能不完善，先这么改</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">7.编译，在shell.c中的main函数设断点就可以单步执行了</p>
<p style="padding-bottom: 0px; margin: 1em 0px 0.5em; padding-left: 0px; padding-right: 0px; padding-top: 0px">icu是<span style="line-height: 21px; color: rgb(0,0,0)">internationalcomponents forunicode，如果需要则需另外下载相关头文件。这个网站上不去，所以没加上去<br /><br /><br /><a href="/Files/AutomateProgram/19854829sqlite3.6.6vs2005.zip">源码下载</a></span></p></div></li>
<p></span></span><br /></font>&nbsp;</p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/148817.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2011-06-16 23:07 <a href="http://www.cppblog.com/AutomateProgram/archive/2011/06/16/148817.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>