Alternatively, start the MySQL server directly and skip the editing with the following command:
mysqld_safe –skip-grant-tables &
Depending on your path environment, you may need to point to the correct directory where mysqld_safe is instead.
Run the following commands to login as the mysql user and connect to mysql user/permission database:
# mysql -u root mysql
Run the update queries to change the MySQL password:
mysql> UPDATE user SET Password=PASSWORD(’newrootpassword’) WHERE User=’root’; mysql> FLUSH PRIVILEGES;
Note: Replace newrootpassword with the new root password for MySQL server. Flush Privileges is needed to making the password change effect immediately.
Exit mysql database client by typing exit.
Stop MySQL server with commands listed at step 2.
Open the mysql server startup script edit in step 3 again and remove the –skip-grant-tables parameter that has been added.
Start MySQL server by using command from step 5 or 6.
For Redhat Linux users, use the following instructions as the root user of Redhat Linux machine:
Stop MySQL process by using command:
# killall mysqld
Start the MySQL server with following options:
# /usr/libexec/mysqld -Sg –user=root &
Start the MySQL client:
# mysql
You should see the following message:
Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1 to server version: 3.xx.xx
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql>
Use mysql database:
mysql> USE mysql
You should see the following message:
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed
Then, update the password for the root user with the following command:
UPDATE user SET password=password(”newpassword”) WHERE user=”root”;
Replace newpassword with your desired password. You should see the following message: