Skip to main content Help Control Panel

Rod Morison Software —  Technotes

Home «   Linux «   Sysadmin «  

How To change the mysql root password (or any mysql password)

Ever inherit a mysql server that no one knew the root password, or perhaps any of the passwords?
# do logged in as root:
/etc/init.d/mysqld stop

# make sure mysqld_safe is not running
ps axu | grep mysql

# NEXT COMMAND ONLY IF mysql IS HUNG AND WONT
# SHUTDOWN NICELY; THE AUTHOR DISCLAIMS ANY DAMAGE
# DUE TO kill -9 'ing...
# If there are still mysql's left, kill -9
# <WARNING> dangerous to do, if kill -9 can
# leave corrupted tables if the server is mid
# transaction!</WARNING>
pkill -9 mysql

# Here's the key: --skip-grant-tables bypasses
# passwords & such...
/usr/sbin/mysqld --skip-grant-tables &
# or, for some distros/installs installations...
/usr/bin/mysqld_safe --skip-grant-tables &

# run mysql client and change pass
mysql
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpass') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> QUIT

# Then, kill the locally running daemon and
# start from /etc/init.d
pkill mysql
/etc/init.d/mysql start

Stay tuned
recent comments
podcasted files
AddThis.com