MySQL: Difference between revisions

From miki
Jump to navigation Jump to search
No edit summary
Line 9: Line 9:
Using '''mysqladmin''':
Using '''mysqladmin''':
<source lang="bash">
<source lang="bash">
unset HISTFILE # <-- DO NOT FORGET IT, OR PWD WILL APPEAR IN ~/.bash_history
mysqladmin -u USERNAME password NEWPWD # Assumes no password set - use user=root for admin pwd
mysqladmin -u USERNAME password NEWPWD # Assumes no password set - use user=root for admin pwd
mysqladmin -u USERNAME -p'OLDPWD' password NEWPWD
mysqladmin -u USERNAME -p'OLDPWD' password NEWPWD
</source>
</source>
If you forget to unset <tt>HISTFILE</tt>, {{red|'''delete your history file immediately'''}}:
{{red|!!! SECURITY HOLE !!!}} &mdash; don't forget to '''DELETE YOUR BASH HISTORY FILE''' !!!
<source lang="bash">
<source lang="bash">
rm ~/.bash_history
rm ~/.bash_history

Revision as of 06:49, 24 June 2015

References

Passwords

Change

Using mysqladmin:

unset HISTFILE                                       # <-- DO NOT FORGET IT, OR PWD WILL APPEAR IN ~/.bash_history
mysqladmin -u USERNAME password NEWPWD               # Assumes no password set - use user=root for admin pwd
mysqladmin -u USERNAME -p'OLDPWD' password NEWPWD

If you forget to unset HISTFILE, delete your history file immediately:

rm ~/.bash_history


Using MySQL commands. First we connect to MySQL server and select table mysql (don't forget to DISABLE HISTORY FILE !!!):

% MYSQL_HISTFILE=/dev/null mysql -u root -p mysql

Here the script:

update user set password=PASSWORD("NEWPWD") where User='USERNAME';
flush privileges;
quit

Recover root password

If the MySQL root password is lost, the same script can be used to define a new password, but it requires to restart the MySQL server with option --skip-grant-tables:

sudo /etc/init.d/mysql stop                   # Stop MySQL server
sudo mysqld_safe --skip-grant-tables &        # Restart it with option not to ask for passwords
sudo su
MYSQL_HISTFILE=/dev/null mysql -u root mysql  # Connect to MySQL, table mysql

Apply the MySQL script above, and restart the server:

sudo /etc/init.d/mysql restart