-
Log on to your system as the user that MySQL server runs as (for example, mysql)
-
Stop the MySQL server if it is running
shell> ps ax | grep mysql
3425 mysqld
shell> kill 3425
- Create a text file containing the password-assignment statement on a single line. (Replace the password with the password that you want to use)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Save the file. This example assumes that you name the file /home/me/mysql-init
.
The file contains the password, so do not save it where it can be read by other users.
If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions that permit mysql to read it.
- Start the MySQL server with the init_file system variable set to name the file:
shell> mysqld --init-file=/home/me/mysql-init &
- After the server has started successfully, delete
/home/me/mysql-init
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.