How to reset MySQL root password in Linux/Unix system

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • ryan
    Member
    • Jun 2008
    • 96

    How to reset MySQL root password in Linux/Unix system

    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.
  • linux7802
    Junior Member
    • Dec 2009
    • 16

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

    We can also refer to the steps provided at https://manage.accuwebhosting.com/knowledgebase its latest and easy way to reset the mysql root password.
    Last edited by admin; 01-21-2023, 12:23 AM.

    Comment

    • WarnerK
      Banned
      • May 2020
      • 34

      #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.

      Comment

      • kumkum sharma
        Junior Member
        • Aug 2020
        • 7

        #4
        AccuWeb.Cloud
        Hi,
        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:
        Code:
        # /etc/init.d/mysql stop
        3. Start MySQL server without password:
        Code:
        # mysqld_safe --skip-grant-tables &
        4. Connect to MySQL:
        Code:
        # mysql -u root
        5. Setup new MySQL root password:
        Code:
        mysql> use mysql; mysql> update user set password=PASSWORD("newpassword") where User='root'; mysql> flush privileges; mysql> quit
        6. Stop MySQL Server:
        Code:
        # /etc/init.d/mysql stop
        7. Stop and start the MySQL service and test it:
        Code:
        # /etc/init.d/mysql stop # /etc/init.d/mysql start # mysql -u root -p

        Comment

        Working...
        X