No announcement yet.

How to reset MySQL root password in Linux/Unix system


Unconfigured Ad Widget

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to reset MySQL root password in Linux/Unix system

    WordPress Hosting on SSD Servers
    How to reset MySQL root password in Linux/Unix system

    1. Log on to your system as the Unix mysql user that the mysqld server runs as.
    2. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on the distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.
    3. Create a text file and place the following statements in it. Replace the password with the password that you want to use.
    4. UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    5. Save the file. For this example, the file will be named /home/me/mysql-init. The file contains the password, so it should not be saved where it can be read by other users.
    6. Start the MySQL server with the special --init-file option:
    7. shell > mysqld_safe --init-file=/home/me/mysql-init &
    8. The server executes the contents of the file named by the --init-file option at startup, changing each root account password.
    9. After the server has started successfully, delete /home/me/mysql-init.
    Last edited by admin; 02-18-2009, 07:53 AM.

  • #2
    Re: How to reset MySQL root password in Linux/Unix system

    We can also refer to the steps provided at its latest and easy way to reset the mysql root password.
    Last edited by Marc_AccuWebHosting; 05-14-2016, 10:40 AM.


    • #3
      Stop the MySQL service. (Ubuntu operating system and Debian) Run the following command: sudo /etc/init.d/mysql stop. ...
      Start MySQL without a password. Run the following command. ...
      Connect to MySQL. ...
      Set a new MySQL root password. ...
      Stop and start the MySQL service. ...
      Log in to the database. ...
      Related articles.


      • #4
        Web Hosting @ $5.95/Month
        I have changed MYSQL root password with below steps, also i don't have much knowledge in Linux commands but these steps worked for me.
        1. First of all, log into the server as root using SSH.
        2. Now, stop MySQL service:
        # /etc/init.d/mysql stop
        3. Start MySQL server without password:
        # mysqld_safe --skip-grant-tables &
        4. Connect to MySQL:
        # mysql -u root
        5. Setup new MySQL root password:
        mysql> use mysql; mysql> update user set password=PASSWORD("newpassword") where User='root'; mysql> flush privileges; mysql> quit
        6. Stop MySQL Server:
        # /etc/init.d/mysql stop
        7. Stop and start the MySQL service and test it:
        # /etc/init.d/mysql stop # /etc/init.d/mysql start # mysql -u root -p



        Sign up for a News Letter Click here to sign up