MySQL
  Home arrow MySQL arrow Page 4 - MySQL User Account Management
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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

MySQL User Account Management
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 19
    2006-07-20


    Table of Contents:
  • MySQL User Account Management
  • 12.2.2 The Grant Tables
  • 12.2.3 Granting and Revoking Privileges
  • 12.2.3.2 The REVOKE Statement
  • 12.2.4 Changing Account Passwords
  • 12.2.5 Specifying Resource Limits

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    MySQL User Account Management - 12.2.3.2 The REVOKE Statement
    ( Page 4 of 6 )

    Use the REVOKE statement to revoke privileges from an account. Its syntax has the following sections:

    • The keyword REVOKE followed by the list of privileges to be revoked

    • An ON clause indicating the level at which privileges are to be revoked

    • A FROM clause that specifies the account name

    Suppose that jim on the local host has SELECT, DELETE, INSERT, and UPDATE privileges on the world database, but you want to change the account so that he has SELECT access only. To do this, revoke those privileges that allow him to make changes:

    REVOKE DELETE, INSERT, UPDATE ON world.* FROM
    'jim'@'localhost';

    To revoke the GRANT OPTION privilege from an account that has it, you must revoke it in a separate statement. For example, if jill has the ability to grant her privileges for the world database to other users, you can revoke that ability as follows:

    REVOKE GRANT OPTION ON world.* FROM
    'jill'@'localhost';

    If you use REVOKE to remove all the privileges enabled by a record in the db, tables_priv, or columns_priv tables, REVOKE removes the record entirely. However, REVOKE does not remove an account's user table record, even if you revoke all privileges for the account. It's necessary to use DELETE to remove a user record. A later example demonstrates this.

    To determine what REVOKE statements are needed to revoke an account's privileges, SHOW GRANTS might be helpful. Consider again the output from SHOW GRANTS for the jen@localhost account:

    mysql> SHOW GRANTS FOR 'jen'@'myhost.example.com';
    +-------------------------------------------------+
    | Grants for jen@myhost.example.com               |
    +-------------------------------------------------+
    | GRANT FILE ON *.* TO 'jen'@'myhost.example.com' |
    | GRANT SELECT ON ´mydb´.* TO                     |
    | 'jen'@'myhost.example.com' | | GRANT UPDATE ON ´test´.´mytable´ TO |
    | 'jen'@'myhost.example.com' | +-------------------------------------------------+

    This output indicates that the account has global, database-level, and table-level privileges. To remove these privileges, convert those GRANT statements to the following corresponding REVOKE statements. The privilege names, privilege levels, and account name must be the same as displayed by SHOW GRANTS:

    mysql> REVOKE FILE ON *.* FROM
    'jen'@'myhost.example.com';
    mysql> REVOKE SELECT ON mydb.* FROM
    'jen'@'myhost.example.com';
    mysql> REVOKE UPDATE ON test.mytable FROM
    'jen'@'myhost.example.com';

    After issuing the REVOKE statements, SHOW GRANTS produces this result:

    mysql> SHOW GRANTS FOR 'jen'@'myhost.example.com';
    +-------------------------------------------------+
    | jen@myhost.example.com;                         |
    +-------------------------------------------------+
    | Grants for jen@myhost.example.com               |
    +-------------------------------------------------+
    | GRANT USAGE ON *.* TO 'jen'@'myhost.example.com'|
    +-------------------------------------------------+

    This means that the account no longer has any privileges, although it does still exist and thus can be used to connect to the server. (In other words, the user table still contains a record for the account, but all the global privileges listed in the record are disabled.) To remove the last trace of the account, use a DELETE statement to remove the user table record, and then tell the server to reload the grant tables:

    mysql> USE mysql;
    mysql> DELETE FROM user WHERE User = 'jen'
    AND Host = 'myhost.example.com';
    mysql> FLUSH PRIVILEGES;

    After that, the account no longer exists and cannot be used to connect to the server.

    12.2.3.3 When Privilege Changes Take Effect

    The effects of changes to the grant tables apply to existing client connections as follows:

    • Table and column privilege changes apply to all statements issued after the changes are made.

    • Database privilege changes apply with the next USE statement.

    • Changes to global privileges and passwords do not apply to connected clients. They apply the next time a client attempts to connect.



     
     
    >>> More MySQL Articles          >>> More By Sams Publishing
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT