简体   繁体   中英

Reset 'root' user password in MySQL 5.7.x+

When I try to reset the MySQL root password on ubuntu system with the following command

update user set password=PASSWORD("newPwd") where User="root";

I see the error as,

ERROR 1054 (42S22): Unknown column 'password' in 'field list'

In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is 'authentication_string'.

Follow these steps to reset 'root' password on Ubuntu

Stop the Service

sudo /etc/init.d/mysql stop

Start MySQL without a password

sudo mysqld_safe --skip-grant-tables &

**Note: the following command didn't work for me**
mysqld --skip-grant-tables &

Connect to MySQL

mysql -uroot

Set a new MySQL root password

mysql>  use mysql;

mysql>  update user set authentication_string=password('yourNewPwd') where user='root';

mysql>  flush privileges;

mysql>  quit

Re-start mysql service

sudo /etc/init.d/mysql stop

sudo /etc/init.d/mysql start

Now, you can login with your updated password

mysql -u root -p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM