MySQL
  Home arrow MySQL arrow Page 5 - Access Granted
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Access Granted
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2001-04-24

    Table of Contents:
  • Access Granted
  • Meet Joe User
  • Beeping Turkeys
  • Born Privileged
  • The Perfect Host
  • Cream Of The Crop
  • The Mechanics

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Access Granted - The Perfect Host


    (Page 5 of 7 )

    A blank entry under the "Host" column in the "db" table implies that the list of allowed hosts should be obtained from the third table, the "hosts" table - which looks like this:

    +-----------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+---------------+------+-----+---------+-------+ | Host | char(60) | | PRI | | | | Db | char(32) | | PRI | | | | Select_priv | enum('N','Y') | | | N | | | Insert_priv | enum('N','Y') | | | N | | | Update_priv | enum('N','Y') | | | N | | | Delete_priv | enum('N','Y') | | | N | | | Create_priv | enum('N','Y') | | | N | | | Drop_priv | enum('N','Y') | | | N | | | Grant_priv | enum('N','Y') | | | N | | | References_priv | enum('N','Y') | | | N | | | Index_priv | enum('N','Y') | | | N | | | Alter_priv | enum('N','Y') | | | N | | +-----------------+---------------+------+-----+---------+-------+

    This separation is more useful than you might think. If you would like to connect and use a database from several different hosts, you would usually have to create a separate entry naming each host in the "db" table. However, with the introduction of the "host" table, you can place the host names in the "host" table while retaining only a single entry (with a blank "Host" field) in the "user" table.

    The "host" table also has privilege fields - these allow you to control the level of access for each database, with the connecting host name as the criteria for operation.

    Here's an example of how the relationship between the "host" and "db" table can be exploited for maximum benefit:

    mysql> SELECT Host, User, Password FROM user; +-----------+------+----------+ | Host | User | Password | +-----------+------+----------+ | | jim | h35472k | +-----------+------+----------+ mysql> SELECT Host, User, Db FROM db +------+------+-------+ | Host | User | Db | +------+------+-------+ | | jim | title | +------+------+-------+ mysql> SELECT Host, Db, Select_priv, Insert_priv FROM host +-------------------+-------+----------------+----------------+ | Host | Db | Select_priv | Insert_priv | +-------------------+-------+----------------+----------------+ | turkey.ix6.com | title | Y | Y | +-------------------+-------+----------------+----------------+ | blackbox.glue.net | title | Y | N | +-------------------+-------+----------------+----------------+ | fireball.home.net | title | Y | Y | +-------------------+-------+----------------+----------------+

    In this case, "jim" will be able to connect to the mySQL server from any of the hosts listed in the "hosts" table, and the privileges assigned can differ on the basis of the host.

    An important point to be noted is that, in the hierarchy of mySQL grant tables, the "user" table comes first, with the "db" and "host" tables below it, and the "tables_priv" and "columns_priv" tables at the bottom. A table at a lower level is referred to only if a higher-level table fails to provide the necessary scope or privileges.

    When deciding whether or not to allow a particular database operation, mySQL takes the privilege fields in all three tables into account. It starts with the "user" table and checks to see if the user has appropriate privileges for the operation being attempted; if not, the "db" and "host" tables are checked to see if privileges are available. It is only after logically parsing the privileges in the different tables that mySQL allows or disallows a specific database request.

    More MySQL Articles
    More By icarus, (c) Melonfire


     

       

    MYSQL ARTICLES

    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway