Change password for MySQL user

Changing the password of an (unprivileged) MySQL user is very simple in principal, but most of the methods I have seen in blog posts etc. are not simple and complete at the same time. This is what I generally do:

[user@host:~/website]
13:00:11 $ mysql -u databaseuser -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56805
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)
 
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> SET PASSWORD FOR 'databaseuser'@'localhost'=PASSWORD('new_password');
Query OK, 0 rows affected (0.03 sec)
 
Ctrl-C

mysql -u databaseuser -p logs in into the MySQL system as the unprivileged user databaseuser using password authentication. The user has permission to change its own password, so this is what I do. A subsequent FLUSH PRIVILEGES; is often recommended and requires administrator privileges. My databaseuser does not have them, so I can not invoke this command. As it turns out, it is not necessary: the password change takes effect immediately (at least for my small setup).

Leave a Reply

Your email address will not be published. Required fields are marked *

Human? Please fill this out: * Time limit is exhausted. Please reload CAPTCHA.