Modify the MySQL administrator password
Change the MySQL root password
Linux and Mac OS X
You can modify the MySQL password using the following command at the shell prompt. Replace the NEW_PASSWORD placeholder with the actual password you wish to set.
$ installdir/mysql/bin/mysqladmin -p -u root password NEW_PASSWORD
Windows
You can modify the MySQL password using the following command at the shell prompt. Replace the NEW_PASSWORD placeholder with the actual password you wish to set.
installdir\mysql\bin\mysqladmin.exe -p -u root password NEW_PASSWORD
Reset the MySQL root password
Linux and Mac OS X
If you don’t remember your MySQL root password, you can follow the steps below to reset it to a new value:
Create a file in /tmp/mysql-init with the content shown below (replace NEW_PASSWORD with the password you wish to use).
If your stack ships MySQL v5.7.x or MySQL v8.x, use this content:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
If your stack ships MySQL v5.6.x or earlier, use this content:
UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root'; FLUSH PRIVILEGES;
TIP: Check the MySQL version with the command
installdir/mysql/bin/mysqladmin --version
orinstalldir/mysql/bin/mysqld \--version
Stop the MySQL server:
$ sudo installdir/ctlscript.sh stop mysql
Start MySQL with the following command:
If your stack ships MySQL v8.x, use this command:
$ sudo installdir/mysql/bin/mysqld_safe --pid-file=installdir/mysql/data/mysqld.pid --datadir=installdir/mysql/data --init-file=/tmp/mysql-init --lower_case_table_names=1 2> /dev/null &
If your stack ships an older version of MySQL, use this command:
$ sudo installdir/mysql/bin/mysqld_safe --pid-file=installdir/mysql/data/mysqld.pid --datadir=installdir/mysql/data --init-file=/tmp/mysql-init 2> /dev/null &
Restart the MySQL server:
$ sudo installdir/ctlscript.sh restart mysql
Remove the script:
$ rm /tmp/mysql-init
Windows
If you don’t remember your MySQL root password, you can follow the steps below to reset it to a new value:
- Stop the MySQL server using the graphic manager tool. Learn how to start or stop the services.
Check the MySQL version:
installdir\mysql\bin\mysqladmin.exe --version
Create a file named mysql-init.txt with the content shown below depending on your MySQL version (replace NEW_PASSWORD with the password you wish to use):
MySQL 5.7.x or MySQL 8.x:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
MySQL 5.6.x or earlier:
UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root'; FLUSH PRIVILEGES;
Start MySQL server with the following command. Remember to replace PATH with the location in which you have saved the mysql-init.txt file:
If your stack ships MySQL v8.x, use this command:
installdir "installdir\mysql\bin\mysqld.exe" --defaults-file="installdir\mysql\my.ini" --init-file="\PATH\mysql-init.txt" --console --lower_case_table_names=1
If your stack ships an older version of MySQL, use this command:
installdir "installdir\mysql\bin\mysqld.exe" --defaults-file="installdir\mysql\my.ini" --init-file="\PATH\mysql-init.txt" --console
- The --init file option is used by the server for executing the content of the mysql-init.txt file at startup, it will change each root account password.
- The --defaults-file option is specified since you have installed MySQL using the Bitnami installer.
- The --console option (optional) has been added in order to show the server output at the console window rather than in the log file.
After some minutes, hit Ctrl-C to force the shutdown.
Restart the MySQL server from the graphic manager tool.
After the server has restarted successfully, delete the mysql-init.txt file.