Create a text file containing the following statements. Replace the password with the password that you want to use.
UPDATE mysql.user SET Password=PASSWORD(‘MyNewPass’) WHERE User=’root’;
Start the MySQL server with the special –init-file option:
shell> mysqld_safe –init-file=/home/me/mysql-init &
The server executes the contents of the file named by the –init-file option at startup, changing each root account password.