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

<channel>
	<title>等待喝彩_OnEcho &#187; 命令行</title>
	<atom:link href="http://www.onecho.com/tag/%e5%91%bd%e4%bb%a4%e8%a1%8c/feed" rel="self" type="application/rss+xml" />
	<link>http://www.onecho.com</link>
	<description>http://www.onecho.com  回声的启示</description>
	<lastBuildDate>Fri, 16 Jul 2010 14:18:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MYSQL命令行模式管理MySql的一点心得</title>
		<link>http://www.onecho.com/2008-09-03/118.html</link>
		<comments>http://www.onecho.com/2008-09-03/118.html#comments</comments>
		<pubDate>Wed, 03 Sep 2008 08:02:32 +0000</pubDate>
		<dc:creator>Kenami</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MYSQL]]></category>
		<category><![CDATA[命令行]]></category>
		<category><![CDATA[心得]]></category>
		<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://blog.oneilove.com.cn/?p=118</guid>
		<description><![CDATA[MySql数据库是中小型网站后台数据库的首选,因为它对非商业应用是免费的.网站开发者可以搭建一个"Linux+Apache+PHP+MySql"平台,这是一个最省钱的高效平台.在使用MySql进行开发时,MySql自带的文档对于新手来说是份很好的参考资料.本文是我在使用MySql中的小小心得。

]]></description>
			<content:encoded><![CDATA[<div id="textbody" class="content">
<p><span style="color: #000000;">MySql数据库是中小型网站后台数据库的首选,因为它对非商业应用是免费的.网站开发者可以搭建一个&#8221;Linux+Apache+PHP+MySql&#8221;平台,这是一个最省钱的高效平台.在使用MySql进行开发时,MySql自带的文档对于新手来说是份很好的参考资料.本文是我在使用MySql中的小小心得。</span></p>
<p><span style="color: #000000;">当前一般用户的开发环境多是Windows或Linux，用户可以到http://www.codepub.com/software/index.html下载相关版本进行安装，在windows中MySql以服务形式存在，在使用前应确保此服务已经启动，未启动可用netstartmysql命令启动。而Linux中启动时可用“/etc/rc.d/init.d/mysqldstart&#8221;命令，注意启动者应具有管理员权限。</span></p>
<p><span style="color: #000000;">刚安装好的MySql包含一个含空密码的root帐户和一个匿名帐户，这是很大的安全隐患，对于一些重要的应用我们应将安全性尽可能提高，在这里应把匿名帐户删除、root帐户设置密码，可用如下命令进行：</span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">usemysql;</span><span style="color: #000000;">deletefromUserwhereUser=&#8221;";</span><span style="color: #000000;">updateUsersetPassword=PASSWORD(&#8217;newpassword&#8217;)whereUser=&#8217;root&#8217;;</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;">如果要对用户所用的登录终端进行限制，可以更新User表中相应用户的Host字段，在进行了以上更改后应重新启动数据库服务，此时登录时可用如下类似命令：</span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql-uroot-p;</span><span style="color: #000000;">mysql-uroot-pnewpassword;</span><span style="color: #000000;">mysqlmydb-uroot-p;</span></p>
<p><span style="color: #000000;">mysqlmydb-uroot-pnewpassword;</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;">上面命令参数是常用参数的一部分，详细情况可参考文档。此处的mydb是要登录的数据库的名称。</span></p>
<p><span style="color: #000000;">在进行开发和实际应用中，用户不应该只用root用户进行连接数据库，虽然使用root用户进行测试时很方便，但会给系统带来重大安全隐患，也不利于管理技术的提高。我们给一个应用中使用的用户赋予最恰当的数据库权限。如一个只进行数据插入的用户不应赋予其删除数据的权限。MySql的用户管理是通过User表来实现的，添加新用户常用的方法有两个，一是在User表插入相应的数据行，同时设置相应的权限；二是通过GRANT命令创建具有某种权限的用户。其中GRANT的常用用法如下：</span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">grantallonmydb.*toNewUserName@HostNameidentifiedby&#8221;password&#8221;;</span><span style="color: #000000;">grantusageon*.*toNewUserName@HostNameidentifiedby&#8221;password&#8221;;</span><span style="color: #000000;">grantselect,insert,updateonmydb.*toNewUserName@HostNameidentifiedby&#8221;password&#8221;;</span></p>
<p><span style="color: #000000;">grantupdate,deleteonmydb.TestTabletoNewUserName@HostNameidentifiedby&#8221;password&#8221;;</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;">若要给此用户赋予他在相应对象上的权限的管理能力，可在GRANT后面添加WITHGRANTOPTION选项。而对于用插入User表添加的用户，Password字段应用PASSWORD函数进行更新加密，以防不轨之人窃看密码。对于那些已经不用的用户应给予清除，权限过界的用户应及时回收权限，回收权限可以通过更新User表相应字段，也可以使用REVOKE操作。</span></p>
<p><span style="color: #000000;">下面给出本人从其它资料获得的对常用权限的解释：</span></p>
<p><strong><span style="color: #000000;">全局管理权限： </span></strong></p>
<p><span style="color: #000000;">FILE:在MySQL服务器上读写文件。 </span></p>
<p><span style="color: #000000;">PROCESS:显示或杀死属于其它用户的服务线程。 </span></p>
<p><span style="color: #000000;">RELOAD:重载访问控制表，刷新日志等。 </span></p>
<p><span style="color: #000000;">SHUTDOWN:关闭MySQL服务。</span></p>
<p><strong><span style="color: #000000;">数据库/数据表/数据列权限： </span></strong></p>
<p><span style="color: #000000;">Alter:修改已存在的数据表(例如增加/删除列)和索引。 </span></p>
<p><span style="color: #000000;">Create:建立新的数据库或数据表。 </span></p>
<p><span style="color: #000000;">Delete:删除表的记录。 </span></p>
<p><span style="color: #000000;">Drop:删除数据表或数据库。 </span></p>
<p><span style="color: #000000;">INDEX:建立或删除索引。 </span></p>
<p><span style="color: #000000;">Insert:增加表的记录。 </span></p>
<p><span style="color: #000000;">Select:显示/搜索表的记录。 </span></p>
<p><span style="color: #000000;">Update:修改表中已存在的记录。</span></p>
<p><strong><span style="color: #000000;">特别的权限： </span></strong></p>
<p><span style="color: #000000;">ALL:允许做任何事(和root一样)。 </span></p>
<p><span style="color: #000000;">USAGE:只允许登录&#8211;其它什么也不允许做。 </span></p>
<p><span style="color: #000000;">最后给出本人在RedHat9.0下的MySql操作演示：</span></p>
<p><span style="color: #000000;">选用数据库的root用户登录</span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">[weiwen@weiwenlinux]$mysql-uroot-p</span><span style="color: #000000;">Enterpassword:MyPassword</span><span style="color: #000000;">mysql&gt;createdatabasemydb;</span></p>
<p><span style="color: #000000;">QueryOK,1rowaffected(0.02sec)</span></p>
<p><span style="color: #000000;">mysql&gt;usemydb;</span></p>
<p><span style="color: #000000;">Databasechanged</span></p>
<p><span style="color: #000000;">mysql&gt;createtableTestTable(Idintaut_incrementprimarykey,</span></p>
<p><span style="color: #000000;">UserNamevarchar(16)notnull,</span></p>
<p><span style="color: #000000;">Addressvarchar(255));</span></p>
<p><span style="color: #000000;">QueryOK,0rowsaffected(0.02sec)</span></p>
<p><span style="color: #000000;">mysql&gt;grantallonmydb.*totest@localhostidentifiedby&#8221;test&#8221;;</span></p>
<p><span style="color: #000000;">QueryOK,0rowsaffected(0.01sec)</span></p>
<p><span style="color: #000000;">mysql&gt;quit</span></p>
<p><span style="color: #000000;">Bye</span></p>
<p><span style="color: #000000;">[weiwen@weiwenlinux]$mysqlmydb-utest-ptest</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;">其中test.sql是用vi编辑好的SQL脚本，其内容为：</span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">InsertintoTestTable(UserName,Address)values(&#8217;Tom&#8217;,&#8217;shanghai&#8217;);</span><span style="color: #000000;">InsertintoTestTable(UserName,Address)values(&#8217;John&#8217;,'beijing&#8217;);</span><span style="color: #000000;">select*fromTestTable;</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;">运行已经编辑好的SQL脚本可以用sourcefilename或.filename。</span></p>
<p><span style="color: #000000;">以上只是对新手的简单练习，要成为一个数据库好手，当以孜孜不倦地追求知识，不断地思考、尝试、再思考。</span></p>
<p><span style="color: #000000;">。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。</span></p>
<p><strong><span style="color: #000000;">MySql常用命令总结 </span></strong></p>
<p><span style="color: #000000;">这两天搞个网站，又用到MySql,可是命令却一个都想不起来，所以，趁这次机会，把这些整理一下，权当作笔记吧，以便自己以后查阅！ </span></p>
<p><strong><span style="color: #000000;">1:使用SHOW语句找出在服务器上当前存在什么数据库： </span></strong></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;SHOWDATABASES; </span></td>
</tr>
</tbody>
</table>
<p><strong><span style="color: #000000;">2:2、创建一个数据库MYSQLDATA </span></strong></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;CreateDATABASEMYSQLDATA;</span></td>
</tr>
</tbody>
</table>
<p> </p>
<p><span style="color: #000000;"><strong>3:选择你所创建的数据库</strong> </span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;USEMYSQLDATA;(按回车键出现Databasechanged时说明操作成功！) </span></td>
</tr>
</tbody>
</table>
<p><strong><span style="color: #000000;">4:查看现在的数据库中存在什么表 </span></strong></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;SHOWTABLES; </span></td>
</tr>
</tbody>
</table>
<p><strong><span style="color: #000000;">5:创建一个数据库表 </span></strong></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;CreateTABLEMYTABLE(nameVARCHAR(20),sexCHAR(1)); </span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;"><strong>6:显示表的结构：</strong> </span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;DESCRIBEMYTABLE;</span></td>
</tr>
</tbody>
</table>
<p> </p>
<p><span style="color: #000000;"><strong>7:往表中加入记录</strong> </span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;insertintoMYTABLEvalues(&#8221;hyq&#8221;,&#8221;M&#8221;); </span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;"><strong>8:用文本方式将数据装入数据库表中</strong>（例如D:/mysql.txt） </span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;LOADDATALOCALINFILE&#8221;D:/mysql.txt&#8221;INTOTABLEMYTABLE; </span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;"><strong>9:导入.sql文件命令</strong>（例如D:/mysql.sql） </span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;usedatabase; </span><span style="color: #000000;">mysql&gt;sourced:/mysql.sql; </span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000000;"><strong>10:删除表</strong> </span></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;dropTABLEMYTABLE; </span></td>
</tr>
</tbody>
</table>
<p><strong><span style="color: #000000;">11:清空表 </span></strong></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;deletefromMYTABLE; </span></td>
</tr>
</tbody>
</table>
<p><strong><span style="color: #000000;">12:更新表中数据 </span></strong></p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="color: #000000;">mysql&gt;updateMYTABLEsetsex=&#8221;f&#8221;wherename=&#8217;hyq&#8217;;</span></td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.onecho.com/2008-09-03/118.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
