November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Resetting MySQL Root Password: Red Hat and CentOS

If you’ve forgotten your MySQL root password (or are involved with some nefarious activity), here is how you can reset that password on a Red Hat (RHEL) system or a CentOS system:

Stop MySQL:

root#  service mysqld stop

Start MySQL in safe mode:

root#  mysqld_safe –skip-grant-tables &

Log into MySQL as root:

root#  mysql -u root

Reset the password:

mysql>  update mysql.user set password=PASSWORD(“YourNewPassW0RD”) where User=’root’;

mysql>  flush privileges; exit;

Log out of MySQL and stop the Safe Mode:

root#  service mysqld stop

Start MySQL in the normal mode:

root#  service mysqld start

Log into MySQL with your new password:

root#  mysql -u root -p

Enter password:

mysql>

Resetting MySQL Root Password: Debian or Ubuntu

 

If you’ve forgotten your MySQL root password (or are involved with some nefarious activity), here is how you can reset that password on a Debian GNU/Linux system or an Ubuntu GNU/Linux system:

Find out the account that the system uses to start and stop MySQL (note that I’ve changed the password for this demo):

root#  cat /etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = 11223344554433
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
user     = debian-sys-maint
password = 11223344554433
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

Log into MySQL with that account:

root#  mysql -u debian-sys-maint -p

Enter password:

mysql>

Change the password:

mysql>  update mysql.user set password=PASSWORD(“YourNewPassW0RD”) where User=’root’;

mysql>  flush privileges; exit;

Log into MySQL as root with your new password:

root#  mysql -u root -p

Enter password:

mysql>

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>