⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1846.html

📁 著名的linux英雄站点的文档打包
💻 HTML
📖 第 1 页 / 共 4 页
字号:
+-------------+------------------------+------+-----+---------+-------+<br>
7 rows in set (0.00 sec)<br>
<br>
columns_priv表指定列级权限。在这里指定的权限适用于一个表的特定列。<br>
<br>
2)MySQL授权表运行机制<br>
MySQL的访问控制分两个步骤:<br>
a)服务器检查是否允许该用户连接。<br>
b)如果该用户有权连接,那么服务器还会检查它的每一个请求是否有足够的权限。比如:用户检索数据库中的一个表需要有这个数据库的select权限,用户删除数据库中的一个表需要有这个数据库的drop权限。<br>
<br>
授权表的user, db, host表使用这两个步骤,tables_priv和columns_priv表只使用第二步(检查请求)。每个授权表包含决定一个权限何时运用的范围列和决定授予哪种权限的权限列。<br>
范围列指定表中的权限何时运用。每个授权表条目包含User和Host列来指定权限何时运用于一个给定用户从给定主机的连接。其他表包含附加的范围列,如db表包含一个Db列指出权限运用于哪个数据库。类似地,tables_priv和columns_priv表包含范围字段,缩小范围到一个数据库中的特定表或一个表的特定列。<br>
下面是user表的Host字段和User字段组合的一些例子:<br>
+-----------------------------+--------+------------------------------------------------+<br>
| Host值 | User值 | 匹配的连接 |<br>
+-----------------------------+--------+-----------------------------------------------+<br>
| 'x.y.z' | 'test' | test用户只能从x.y.z连接数据库 |<br>
+-----------------------------+--------+-----------------------------------------------+<br>
| 'x.y.z' | '' | 任何用户可以从x.y.z连接数据库 |<br>
+-----------------------------+--------+-----------------------------------------------+<br>
| '%' | 'test' | test用户可以从任意主机连接数据库 |<br>
+-----------------------------+--------+----------------------------------------------+<br>
| '' | '' | 任何用户可以从任意主机连接数据库 |<br>
+-----------------------------+--------+-----------------------------------------------+<br>
| '%.y.z' | 'test' | test用户可以从y.z域的任意主机连接数据库 |<br>
+-----------------------------+--------+----------------------------------------------+<br>
| 'x.y.% ' | 'test' | test用户可以从x.y.net, x.y.com, x.y.edu等主机连接数据库|<br>
+-----------------------------+--------+----------------------------------------------+<br>
| '192.168.1.1' | 'test' | test用户可以从IP地址为192.168.1.1的主机连接数据库 |<br>
+-----------------------------+--------+---------------------------------------------+<br>
| '192.168.1.% ' | 'test' | test用户可以从C类子网192.168.1中的任意主机连接数据库 |<br>
+-----------------------------+--------+---------------------------------------------+<br>
| '192.168.1.0/255.255.255.0' | 'test' | 同上 |<br>
+-----------------------------+--------+--------------------------------------------+<br>
SQL的字符串通配符%表示匹配任意字符,可以是0个字符,通配符_表示匹配一个字符。<br>
<br>
权限列指出在范围列中指定的用户拥有何种权限。该表使用GRANT语句的权限名称。对于绝大多数在user、db和host表中的权限列的名称与GRANT语句中有明显的联系。如Select_priv对应于SELECT权限。<br>
<br>
3)授权表使用举例<br>
grant用于给增加用户和创建权限,revoke用于删除用户权限。<br>
下面是一些用grant增加用户和创建权限的例子:<br>
<br>
mysql&gt; grant all privileges on *.* to test@localhost identified by 'test' with grant option;<br>
<br>
这句增加一个本地具有所有权限的test用户(超级用户),密码是test。ON子句中的*.*意味着"所有数据库、所有表"。with grant option表示它具有grant权限。<br>
<br>
mysql&gt; grant select,insert,update,delete,create,drop privileges on test.* to test1@'192.168.1.0/255.255.255.0' identified by 'test';<br>
<br>
这句是增加了一个test1用户,口令是test,但是它只能从C类子网192.168.1连接,对test库有select,insert,update,delete,create,drop操作权限。<br>
用grant语句创建权限是不需要再手工刷新授权表的,因为它已经自动刷新了。<br>
给用户创建权限还可以通过直接修改授权表:<br>
<br>
mysql&gt; insert into user values("localhost","test",password("test"),"Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y");<br>
mysql&gt; flush privileges;<br>
<br>
这两句和上面第一句grant的效果是一样的,也是增加了一个本地的test超级用户。我们看到用grant方便多了,而且还不需flush privileges<br>
。<br>
mysql&gt; insert into user (host,user,password) values("192.168.1.0/255.255.255.0","test1",PASSWORD("test"));<br>
mysql&gt; insert into db values("192.168.1.0/255.255.255.0","test","test1","Y","Y","Y","Y","Y","Y","N","N","N","N")<br>
mysql&gt; flush privileges;<br>
<br>
这三句和上面第二句grant的效果也是一样的,也是增加了一个只能从C类子网192.168.1连接,对test库有select,insert,update,delete,create,drop操作权限的test1用户,口令是test。要取消一个用户的权限,使用revoke语句。revoke的语法非常类似于grant语句,除了to用from取代并且没有identified by和with grant<br>
option子句,下面是用revoke删除用户权限的例子:<br>
<br>
mysql&gt; revoke all on test.* from test1@'192.168.1.0/255.255.255.0';<br>
<br>
这句revoke就撤消了上面第二句grant创建的权限,但是test1用户并没有被删除,必须手工从user表删除:<br>
<br>
mysql&gt; delete from user where user='test1';<br>
mysql&gt; flush privileges;<br>
<br>
这样,test1用户就彻底删除了。<br>
<br>
这些只是MySQL授权表的简单使用,更多详细的资料请见MySQL提供的手册。<br>
<br>
3、编程需要注意的一些问题<br>
<br>
不管是用哪种程序语言写连接MySQL数据库的程序,有一条准则是永远不要相信用户提交的数据!<br>
对于数字字段,我们要使用查询语句:SELECT * FROM table WHERE ID='234',不要使用SELECT * FROM table WHERE ID=234这样的查询语句。MySQL会自动把字串转换为数字字符并且去除非数字字符。如果用户提交的数据经过了mysql_escape_string处理,这样我们就可以完全杜绝了sql inject攻击,关于sql inject攻击请参考下面链接的文章:<br>
http://www.spidynamics.com/papers/SQLInjectionWhitePaper.pdf<br>
http://www.ngssoftware.com/papers/advanced_sql_injection.pdf<br>
各种编程语言该注意的问题:<br>
<br>
1)所有Web程序:<br>
a)尝试在Web表单输入单引号和双引号来测试可能出现的错误,并找出原因所在。<br>
b)修改URL参数带的%22 ('"'), %23 ('#'), 和 %27 (''')。<br>
c)对于数字字段的变量,我们的应用程序必须进行严格的检查,否则是非常危险的。<br>
d)检查用户提交的数据是否超过字段的长度。<br>
e)不要给自己程序连接数据库的用户过多的访问权限。<br>
<br>
2)PHP:<br>
a)检查用户提交的数据在查询之前是否经过addslashes处理,在PHP 4.0.3以后提供了基于MySQL C API的函数mysql_escape_string()。<br>
<br>
3)MySQL C API:<br>
a)检查查询字串是否用了mysql_escape_string() API调用。<br>
<br>
4)MySQL++:<br>
a)检查查询字串是否用了escape和quote处理。<br>
<br>
5)Perl DBI:<br>
a)检查查询字串是否用了quote()方法。<br>
<br>
6)Java JDBC:<br>
a)检查查询字串是否用了PreparedStatement对象。<br>
<br>
4、一些小窍门<br>
<br>
1)如果不慎忘记了MySQL的root密码,我们可以在启动MySQL服务器时加上参数--skip-grant-tables来跳过授权表的验证 (./safe_mysqld --skip-grant-tables &),这样我们就可以直接登陆MySQL服务器,然后再修改root用户的口令,重启MySQL就可以用新口令登陆了。<br>
<br>
2)启动MySQL服务器时加上--skip-show-database使一般数据库用户不能浏览其它数据库。<br>
<br>
3)启动MySQL服务器时加上--chroot=path参数,让mysqld守护进程运行在chroot环境中。这样SQL语句LOAD DATA INFILE和SELECT ... INTO OUTFILE就限定在chroot_path下读写文件了。这里有一点要注意,MySQL启动后会建立一个mysql.sock文件,默认是在/tmp目录下。使用了chroot后,MySQL会在chroot_path/tmp去建立mysql.sock文件,如果没有chroot_path/tmp目录或启动MySQL的用户没有这个目录写权限就不能建立mysql.sock文件,MySQL会启动失败。比如我们加了--chroot=/usr/local/mysql/启动参数,那么最好建立一个启动MySQL的用户能写的<br>
/usr/local/mysql/tmp目录,当然我们也可以用--socket=path来指定mysql.sock文件的路径,但这个path一定要在chroot_path里面。<br>
<br>
4)启动MySQL服务器时加上--log-slow-queries[=file]参数,这样mysqld会把SQL命令执行时间超过long_query_time的写入file文件。如果没有指定=file,mysqld默认会写到数据目录下的hostname-slow.log。如果只指定了filename,没有指定路径,那么mysqld也会把filename写到数据目录下。我们通过这个日志文件可以找出执行时间超长的查询语句,然后尽可能的优化它减轻MySQL服务器的负担。<br>
<br>
5)如果我们只需本机使用MySQL服务,那么我们还可以加上--skip-networking启动参数使MySQL不监听任何TCP/IP连接,增加安全性。(非常推荐)<br>
<br>
6)MySQL的更多mysqld启动选项请见MySQL手册4.16.4 mysqld Command-line Options<br>
<br>
5、References<br>
MySQL Manual(http://www.mysql.com/documentation/index.html)<br>
晏子的MySQL管理员指南(http://clyan.hongnet.com/index.html)<br>
Access Granted(http://www.devshed.com/Server_Side/MySQL/Access)
</FONT><br>
                                      </TD>
                                    </TR>
                                <TR>
                                <TD colSpan=2><FONT 
                                class=middlefont></FONT><BR>
                                        <FONT 
                                class=normalfont>全文结束</FONT> </TD>
                                    </TR>
                                <TR>
                                <TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2 
                                height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
                        <TD vAlign=top width="20%" 
                      background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2> 
                          <DIV align=center> 
                            <table class=tableoutline cellspacing=1 cellpadding=4 
                        width="100%" align=center border=0>
                              <tr class=firstalt> 
                                <td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
                                <font class=normalfont><b>所有分类</b></font></td>
                              </tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td>    </tr>  </table></td></tr>                            </table>
                          </DIV></TD></TR>
                    <TR vAlign=top>
                        <TD width="80%"> 
                          <DIV align=center><BR>
                          </DIV>
                        </TD></TR></TBODY></TABLE></TD></TR>
                </TABLE></TD></TR>
          </TABLE>
      <TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee 
        border=0><TBODY>
        <TR>
          <TD width="50%">
              <P><FONT class=middlefont>版权所有 &copy; 2004 <A 
            href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
                违者必究. </FONT></P>
            </TD>
          <TD width="50%">
              <DIV align=right><FONT class=middlefont>Powered by: <A 
            href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
            </TD></TR></TBODY></TABLE>
      <CENTER></CENTER></TD></TR>
    </TABLE></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -