MySQL
  Home arrow MySQL arrow Page 4 - Managing MySQL User Accounts
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 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 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

Managing MySQL User Accounts
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2006-06-15

    Table of Contents:
  • Managing MySQL User Accounts
  • 4.5.2 Adding New User Accounts to MySQL
  • 4.5.3 Removing User Accounts from MySQL
  • 4.5.5 Assigning Account Passwords
  • 4.5.6 Keeping Your Password Secure
  • 4.5.7.3 Setting Up SSL Certificates for MySQL
  • 4.5.7.4 SSL GRANT Options

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Managing MySQL User Accounts - 4.5.5 Assigning Account Passwords


    (Page 4 of 7 )

    Passwords may be assigned from the command line by using the mysqladmin command:

    shell> mysqladmin -u user_name -h host_name
    password "newpwd"

    The account for which this command resets the password is the one with a user table record that matches user_name in the User column and the client host from which you connect in the Host column.

    Another way to assign a password to an account is to issue a SET PASSWORD statement:

    mysql> SET PASSWORD FOR 'jeffrey'@'%' =
    PASSWORD('biscuit');

    Only users such as root with update access to the mysql database can change the password for other users. If you are not connected as an anonymous user, you can change your own password by omitting the FOR clause:

    mysql> SET PASSWORD = PASSWORD('biscuit');

    You can also use a GRANT USAGE statement at the global level (ON *.*) to assign a password to an account without affecting the account's current privileges:

    mysql> GRANT USAGE ON *.* TO 'jeffrey'@'%'
    IDENTIFIED BY 'biscuit';

    Although it is generally preferable to assign passwords using one of the preceding methods, you can also do so by modifying the user table directly:

    • To establish a password when creating a new account, provide a value for the Password column:

      shell> mysql -u root mysql
      mysql> INSERT INTO user (Host,User,Password)
      -> VALUES('%','jeffrey',PASSWORD
      ('biscuit'));
      mysql> FLUSH PRIVILEGES;

    To change the password for an existing account, use UPDATE to set the Password column value:

    shell> mysql -u root mysql
    mysql> UPDATE user SET Password =
    PASSWORD('bagel')
    -> WHERE Host = '%' AND User = 'francis'; mysql> FLUSH PRIVILEGES;

    When you assign an account a password using SET PASSWORD, INSERT, or UPDATE, you must use the PASSWORD() function to encrypt it. (The only exception is that you need not use PASSWORD() if the password is empty.) PASSWORD() is necessary because the user table stores passwords in encrypted form, not as plaintext. If you forget that fact, you are likely to set passwords like this:

    shell> mysql -u root mysql
    mysql> INSERT INTO user (Host,User,Password)
    -> VALUES('%','jeffrey','biscuit'); mysql> FLUSH PRIVILEGES;

    The result is that the literal value 'biscuit' is stored as the password in the user table, not the encrypted value. When jeffrey attempts to connect to the server using this password, the value is encrypted and compared to the value stored in the user table. However, the stored value is the literal string 'biscuit', so the comparison fails and the server rejects the connection:

    shell> mysql -u jeffrey -pbiscuit test
    Access denied

    If you set passwords using the GRANT ... IDENTIFIED BY statement or the mysqladmin password command, they both take care of encrypting the password for you. The PASSWORD() function is unnecessary.

    Note: PASSWORD() encryption is different from Unix password encryption. See Section 4.5.1, "MySQL Usernames and Passwords."

    More MySQL Articles
    More By Sams Publishing


       · This article is an excerpt from the book "MySQL Administrator's Guide," published by...
     

    Buy this book now. This article is excerpted from the book MySQL Administrator's Guide, written by Paul Dubois (Sams; ISBN: 0672326345). Check it out today at your favorite bookstore. Buy this book now.

       

    MYSQL ARTICLES

    - 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...
    - Creating the Blog Script for a PHP/MySQL Blo...

    BlackBerry VTS




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