How to reset or change MySQL's root password: MySQL Password Reset Guide
P粉458913655
P粉458913655 2023-08-20 15:35:51
0
2
470
<p>How to change MySQL root password and username on Ubuntu server? Do I need to stop the mysql service before making any changes? </p> <p>I also installed phpmyadmin. Will phpmyadmin be updated automatically? </p>
P粉458913655
P粉458913655

reply all(2)
P粉306523969

The only way that worked for me was the one described here (I'm running ubuntu 14.04). For clarity, here are the steps I followed:

  1. sudo vim /etc/mysql/my.cnf
  2. Add the following lines at the end:

    [mysqld]
    
    skip-grant-tables
  3. sudo service mysql restart

  4. mysql -u root

  5. use mysql

  6. select * from mysql.user where user = 'root'; - look at the top to determine if the password column is called password or authentication_string

  7. UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the correct password field from above

  8. FLUSH PRIVILEGES;

  9. exit

  10. sudo vim /etc/mysql/my.cnf

  11. If you want to maintain security standards, delete the line added in step 2.

  12. sudo service mysql restart

Reference: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

P粉135799949

Set/change/reset MySQL's root password on Ubuntu Linux. Enter the following command in the terminal.

  1. Stop the MySQL server: sudo /etc/init.d/mysql stop
  2. (In some cases, if /var/run/mysqld does not exist, you need to create it first: sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld
  3. StartmysqldConfiguration: sudo mysqld --skip-grant-tables &
  4. Log in to MySQL as root: mysql -u root mysql
  5. Replace YOURNEWPASSWORD with your new password:

For MySQL < 8.0

UPDATE mysql.user SET Password = PASSWORD('YOURNEWPASSWORD') WHERE User = 'root';
FLUSH PRIVILEGES;

If your MySQL uses the new authentication plugin, you need to use: update user set plugin="mysql_native_password" where User='root'; before refreshing permissions.

Note: This method is not considered the most secure way to reset your password, but it works.

For MySQL >= 8.0

FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';
FLUSH PRIVILEGES;

last step:

As mentioned in @lambart's comment, you may need to kill the temporary passwordless mysql process you started, i.e. sudo killall -9 mysqld, and then start the normal daemon: sudo service mysql start

References:

  1. Set/Change/Reset MySQL’s root password on Ubuntu Linux
  2. How to reset Root password (v5.6)
  3. How to reset Root password (v8.0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!