I have been trying lớn reset my MySQL root password. I have run mysqld_safe --skip-grant-tables, updated the root password, và checked the user table to make sure it is there.

Bạn đang xem: Changing the root password for linux

Once restarting the MySQL daemon I tried logging in with the new root password that I just set và still get Access denied for user "root" errors. I have also tried completely removing and reinstalling MySQL (including removing the my.cnf file) & still no luck. What can I vày next?


*

*

*

*

"localhost" IDENTIFIED BY "MyNewPass";You can find Resetting the Root Password in the MySQL documentation.


*

Have a look at this from the MySQL reference manual:

First log in lớn MySQL:

mysql -u root -pThen at the mysql prompt, run:

UPDATE mysql.user mix Password=PASSWORD("MyNewPass") WHERE User="root";Then

FLUSH PRIVILEGES;Look at this page for more information: Resetting the Root Password: Unix Systems

UPDATE:

For some versions of mysql, the password column is no longer available và you"ll get this error:

ERROR 1054 (42S22): Unknown column "Password" in "field list"

In this case, use ALTER USER as shown in the answer below.


chia sẻ
Improve this answer
Follow
edited Nov 23, 2021 at 11:24
andromeda
3,48744 gold badges2525 silver badges3737 bronze badges
answered Aug 7, 2013 at 9:51
VSBVSB
8,8081111 gold badges6363 silver badges128128 bronze badges
3
địa chỉ a bình luận |
33
Please follow the below steps.

sudo service mysql stopsudo mysqld_safe --skip-grant-tablessudo service mysql startsudo mysql -u rootuse mysql;show tables;describe user;update user mix authentication_string=password("1111") where user="root";FLUSH PRIVILEGES;

Log in with password "1111".


nội dung
Improve this answer
Follow
edited Sep 22, 2021 at 20:54
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Feb 27, 2017 at 11:16
Lokesh GLokesh G
76188 silver badges1818 bronze badges
6
| Show 1 more bình luận
33
This is the updated answer for WAMP v3.0.6 and up.

In the MySQL command-line client, phpMyAdmin or any MySQL GUI:

UPDATE mysql.userSET authentication_string=PASSWORD("MyNewPass")WHERE user="root";FLUSH PRIVILEGES;In MySQL version 5.7.x there is no more password field in the MySQL table. It was replaced with authentication_string. (This is for the terminal/CLI.)

In the MySQL command-line client, phpMyAdmin or any MySQL GUI:

UPDATE mysql.user set authentication_string=PASSWORD("MyNewPass") WHERE user="root";FLUSH PRIVILEGES;
giới thiệu
Improve this answer
Follow
edited Sep 22, 2021 at 21:02
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Apr 20, 2017 at 4:33
Robert Anthony S. TribianaRobert Anthony S. Tribiana
9841111 silver badges1616 bronze badges
8
| Show 3 more comments
28
I searched around as well and probably some answers bởi vì fit for some situations,

my situation is Mysql 5.7 on a Ubuntu 18.04.2 LTS system:

(get root privileges)

$ sudo bash(set up password for root db user + implement security in steps)

# mysql_secure_installation(give access lớn the root user via password in stead of socket)

(+ edit: apparently you need khổng lồ set the password again?)

(don"t set it khổng lồ "mySecretPassword"!!!)

# mysql -u rootmysql> USE mysql;mysql> UPDATE user mix plugin="mysql_native_password" WHERE User="root";mysql> set password for "root"
"localhost" = PASSWORD("mySecretPassword"); mysql> FLUSH PRIVILEGES;mysql> exit;# service mysql restartMany thanks khổng lồ zetacu (and erich) for this excellent answer (after searching a couple of hours...)

Enjoy :-D

S.

Edit (2020):

This method doesn"t work anymore, see this question for future reference...


share
Improve this answer
Follow
edited Sep 24, 2021 at 16:02
answered May 10, 2019 at 13:33
MadBoomyMadBoomy
2,18133 gold badges2222 silver badges3333 bronze badges
3
add a comment |
24
I found it! I forgot lớn hash the password when I changed it. I used this query lớn solve my problem:

update user mix password=PASSWORD("NEW PASSWORD") where user="root";

I forgot the PASSWORD("NEW PASSWORD") & just put in the new password in plain text.


cốt truyện
Improve this answer
Follow
edited Sep 22, 2021 at 19:31
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Sep 25, 2011 at 2:14
nicknick
1,94822 gold badges1212 silver badges1414 bronze badges
6
| Show 1 more bình luận
18
On MySQL 8.0.4+

To update the current root user:

select current_user();set password = "new_password";To update another user:

set password for "otherUser"
"localhost" = "new_password";To phối the password policy before updating the password:

set global validate_password.policy = 0;set password = "new_password";set password for "otherUser"
"localhost" = "new_password";Another / better way khổng lồ update the root password:

mysql_secure_installationDo you want khổng lồ stick with 5.x authentication, so you can still use legacy applications?

In my.cnf file

default_authentication_plugin = mysql_native_passwordTo update root:

set global validate_password.policy = 0;alter user "root"
"localhost" identified with mysql_native_password by "new_password";
share
Improve this answer
Follow
edited Sep 23, 2021 at 2:20
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Jul 7, 2019 at 6:14
CarlitoCarlito
18111 silver badge44 bronze badges
0
địa chỉ cửa hàng a comment |
13
On MySQL 8 you need to specify the password hashing method:

ALTER USER "root"
"localhost" IDENTIFIED WITH caching_sha2_password BY "new-password";
cốt truyện
Improve this answer
Follow
answered Dec 31, 2020 at 13:37
HokaschaHokascha
1,5111818 silver badges3939 bronze badges
địa chỉ cửa hàng a comment |
12
This worked for me -

ALTER USER "root"
"localhost" IDENTIFIED BY "MyNewPass";

Chapter 4 Resetting the Root Password: Windows Systems


tóm tắt
Improve this answer
Follow
edited Sep 23, 2021 at 2:21
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Dec 9, 2019 at 13:22
EdGziEdGzi
1,11477 silver badges2222 bronze badges
3
showroom a bình luận |
11
For MySQL 5.7.6 & later:

ALTER USER "root"
"localhost" IDENTIFIED BY "MyNewPass";For MySQL 5.7.5 & earlier:

SET PASSWORD FOR "root"
"localhost" = PASSWORD("MyNewPass");
nói qua
Improve this answer
Follow
answered Nov 4, 2018 at 14:20
Eagle_EyeEagle_Eye
1,02411 gold badge1414 silver badges2525 bronze badges
showroom a bình luận |
8
For me, only these steps could help me setting the root password on version 8.0.19:

mysqlSELECT user,authentication_string FROM mysql.user;ALTER USER "root"
"localhost" IDENTIFIED WITH mysql_native_password BY "your_pass_here";FLUSH PRIVILEGES;SELECT user,authentication_string FROM mysql.user;If you can see changes for the root user, then it works.Source: Can"t mix root password MySQL Server


nội dung
Improve this answer
Follow
edited Sep 23, 2021 at 2:32
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Feb 4, 2021 at 11:52
Sergey ZaharchenkoSergey Zaharchenko
1,04011 gold badge1010 silver badges88 bronze badges
2
add a phản hồi |
6
You have to lớn reset the password! Steps for Mac OS X (tested & working) & Ubuntu:

Stop MySQL

sudo /usr/local/mysql/support-files/mysql.server stopStart it in safe mode:

sudo mysqld_safe --skip-grant-tables(The above line is the whole command.)

This will be an ongoing command until the process is finished, so open another shell/terminal window & log in without a password:

mysql -u rootmysql> UPDATE mysql.user phối Password=PASSWORD("password") WHERE User="root";Start MySQL

sudo /usr/local/mysql/support-files/mysql.server startYour new password is "password".


mô tả
Improve this answer
Follow
edited Sep 22, 2021 at 20:09
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Feb 19, 2015 at 7:51
tk_tk_
14.5k77 gold badges7676 silver badges8686 bronze badges
2
địa chỉ a bình luận |
5
For the current latest MySQL version (8.0.16), none of these answers worked for me.

After looking at several different answers và combining them together, this is what I ended up using that worked:

update user set authentication_string="test" where user="root";
cốt truyện
Improve this answer
Follow
edited Sep 23, 2021 at 1:55
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered May 29, 2019 at 22:48
SuhasSuhas
51044 silver badges1111 bronze badges
1
add a phản hồi |
4
Using the mysqladmin command-line utility lớn alter the MySQL password:

mysqladmin --user=root --password=oldpassword password "newpassword"Source


cốt truyện
Improve this answer
Follow
answered Dec 1, 2018 at 6:00
DarushDarush
10.4k88 gold badges5757 silver badges5757 bronze badges
showroom a bình luận |
3
I tried the answer from kta, but it didn"t work for me.

I am using MySQL 8.0.

This worked for me in the MySQL command-line client (executable mysql):

SET PASSWORD FOR "root"
"localhost" = "yourpassword"


giới thiệu
Improve this answer
Follow
edited Sep 23, 2021 at 1:46
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Mar 11, 2019 at 11:35
chainstairchainstair
55044 silver badges1616 bronze badges
3
địa chỉ a comment |
3
This is for Mac users.

On 8.0.15 (maybe already before that version) the PASSWORD() function does not work. You have to lớn do:

Make sure you have Stopped MySQL first (above).Run the server in safe mode with privilege bypass:

sudo mysqld_safe --skip-grant-tablesReplace this mysqld_safe with your MySQL path lượt thích in my case it was

sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tablesthen you have to lớn perform the following steps.

mysql -u rootUPDATE mysql.user mix authentication_string=null WHERE User="root";FLUSH PRIVILEGES;exit;Then

mysql -u rootALTER USER "root"
"localhost" IDENTIFIED WITH caching_sha2_password BY "yourpasswd";
tóm tắt
Improve this answer
Follow
edited Sep 23, 2021 at 2:26
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Dec 29, 2020 at 19:48
Supreet SinghSupreet Singh
63688 silver badges88 bronze badges
1
địa chỉ cửa hàng a comment |
2
In MySQL 5.7, the password is replacedwith "authentication_string". Use

update user mix authentication_string=password("myfavpassword") where user="root";
tóm tắt
Improve this answer
Follow
edited Sep 22, 2021 at 21:08
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered May 14, 2018 at 11:34
Kamal ReddyKamal Reddy
2,55044 gold badges2525 silver badges3636 bronze badges
add a phản hồi |
2
So many comments, but I was helped by this method:

sudo mysqladmin -u root password "my password"In my case after installation I had got the MySQL service without a password for the root user, và I needed to lớn set the password for my security.


giới thiệu
Improve this answer
Follow
edited Sep 23, 2021 at 2:17
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Jun 11, 2019 at 7:57
Konstantin RomanovskyKonstantin Romanovsky
2922 bronze badges
1
showroom a comment |
1
A common error I run into from time to lớn time, is that I forget the -p option, so be sure to lớn use:

mysql -u root -p
chia sẻ
Improve this answer
Follow
edited Sep 22, 2021 at 18:39
Peter Mortensen
29.8k2121 gold badges9898 silver badges124124 bronze badges
answered Sep 23, 2011 at 19:53
Marian TheisenMarian Theisen
5,9302626 silver badges3838 bronze badges
0
showroom a phản hồi |
1
Now just use:

SET PASSWORD FOR = ""Because "SET PASSWORD FOR = PASSWORD("")" is deprecated and will be removed in a future release.(Warning in 04/12 2021)Please use set PASSWORD FOR = "" instead.

Update 04/12 2021 AM 2:22:07 UTC/GMT -5 hours.

Use the following statement to lớn modify directly in the mysql command line:

mysql> mix PASSWORD FOR"root"
"localhost" = PASSWORD("newpass");or 1.The terminal enters the bin directory of MySQL

cd /usr/local/mysql/bin2.Open MySQL

mysql -u root -p3.At this time you can use your mặc định password

4.Perform operations in MySQL at this time

show databases;5.You will be prompted lớn reset the root user password.

So how to lớn reset the root password? I checked a lot of information but it didn’t take effect.

Including entering to lớn modify the database in safe mode, using the mysqladmin command:"Mysqladmin -u root password"your-new-password""etc.,Will not work.

The correct steps are as follows:

1.It is still in the cd /usr/local/mysql/bin/ directory

2.sudo su

After entering, you will be asked to enter your computer password.

When you enter it, nothing is displayed. After you enter it, press Enter

Then press enter

3.Cross the authorization verification

sh-3.2# ./mysqld_safe --skip-grant-tables &If the execution of the command is stopped, và the execution has been completed at this time,

press Enter directly, và then exit lớn exit:

sh-3.2# exit4.Re-enter MySQL at this time, no -p parameter, no password

./mysql -u root5.Select the database MySQL (here MySQL refers to lớn a database in MySQL,

there are other databases in MySQL, you can view it through show databases;)

use mysql;6.Update the password of the root user in the database table:

update user set authentication_string=‘123456’ where User="root";Note: The password field here is authentication_string,

not the password circulated on the Internet.

It is estimated that MySQL was updated later.

Xem thêm: Cách Tăng Điểm Tiềm Năng, Khả Năng Thiếu Lâm Vltk 1 Mobile, Cách Tăng Điểm Thiếu Lâm Vltk 1 Mobile

Re-enter MySQL & use the password you just set, is it all right?

Because you have just set to lớn bypass the authorization authentication,

you can log in to MySQL directly without a password.

My stupid way is lớn restart the computer và log in to lớn MySQL with the password again to see if the modification is effective;