Reset MySQL root password on Bitnami server

To reset MySQL root password on Bitnami server, first check MySQL server version you are running.

mysql --version

Create a file

vi /tmp/mysql-init

Add following text

For MySQL 5.7 or MySQL 8

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY 'NEW_PASSWORD';

For MySQL 5.6

UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';
FLUSH PRIVILEGES;

In above code, replace NEW_PASSWORD with your new MySQL root password.

Stop MySQL

/opt/bitnami/ctlscript.sh stop mysql

Reset MySQL root password by running

MySQL 5.7/MySQL 8

/opt/bitnami/mysql/bin/mysqld_safe --pid-file=/opt/bitnami/mysql/data/mysqld.pid --datadir=/opt/bitnami/mysql/data --init-file=/tmp/mysql-init --lower_case_table_names=1 2> /dev/null &

If you are using MySQL 5.6 or older, run

/opt/bitnami/mysql/bin/mysqld_safe --pid-file=/opt/bitnami/mysql/data/mysqld.pid --datadir=/opt/bitnami/mysql/data --init-file=/tmp/mysql-init 2> /dev/null &

Restart MySQL

/opt/bitnami/ctlscript.sh restart mysql

Now you should be able to login to MySQL server with command

mysql -u root -p'NEW_PASSWORD'

See Bitnami, Reset MySQL root Password

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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