• Changing a MySQL User Password

    1. Stop the Server

    You need to stop the MySQL server process using one of the following methods:

    /etc/init.d/mysql stop
    service mysql stop

    2. Start the Server Without Privilege Checks

    In this mode, the server will grant full permissions even if no password is provided.

    mysqld_safe --skip-grant-tables

    3. Change the Password

    Now nothing prevents us from connecting to the server and manually changing the password for the required user:

    mysql -u root

    The following commands are entered in the MySQL command-line interface:

    USE mysql;
    UPDATE user SET password = PASSWORD("SECRET-PASSWORD") WHERE user = "root";
    FLUSH PRIVILEGES;
    QUIT;

    4. Done? Almost

    The password has already been changed. But do not forget that the server is still running without permission checks. We need to stop it again and start it in normal mode.

    /etc/init.d/mysql stop
    /etc/init.d/mysql start
    
    service mysql stop
    service mysql start

    Now that is everything. Note that the initialization scripts may be in a different directory on your system.