Log on to your system as the Unix user that the MySQL server runs as (for example, mysql).
Stop the MySQL server if it is running. You did that with:
su /etc/init.d/mysql stop
Create a text file containing the following statement on a single line. Replace the password with the password that you want to use.
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
Save the file. This example names 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 special --init-file
option:
shell> /usr/sbin/mysqld --init-file=/home/me/mysql-init &
The server executes the contents of the file named by the --init-file
option at startup, changing the 'root'@'localhost'
account password.
After the server has started successfully, delete /home/me/mysql-init
.
Kill mysqld
and start it with:
su /etc/init.d/mysql start