mysql reset password_MySQL 8 Set or reset user password

Reset of MySQL password can be done in several ways depending of the:

OS

are you connected

user rights

In this post:

MySQL 8 set new root password

MySQL problems related to root authentication

Not able to connect with root and no password

1699 SET PASSWORD has no significance for user 'root'@'localhost' as authentication plugin does not support it.

1287 'SET PASSWORD FOR = PASSWORD('')' is deprecated and will be removed in a future release. Please use SET PASSWORD FOR = '' instead

MySQL remove root password

MySQL set new root password

Windows Resetting the Root Password

Ubuntu Resetting the Root Password

Reset the user by query

Reset password from MySQL Workbench

MySQL 8 set new root password

If you can log in to your MySQL server and you wanto to change your password by query you can do it by:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

复制代码

or removing the root password:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

复制代码

MySQL problems related to root authentication

Not able to connect with root and no password

If you remove your root password or set it to null then you may experience problems when you try to connect with root. It's advisable to create another DBA user while playing with these settings.

One of the reasons to not be able to connect would be: auth_socket plugin. This is a new change since 5.7:

If we want to configure a password, we need to change the plugin and set the password at the same time, in the same command. First changing the plugin and then setting the password won’t work, and it will fall back to auth_socket again. So, run:

复制代码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';

复制代码

For more information you can check the link in references

1699 SET PASSWORD has no significance for user 'root'@'localhost' as authentication plugin does not support it.

In case that you are trying to change your root password(or other user password without success you can check previous section.

1287 'SET PASSWORD FOR = PASSWORD('')' is deprecated and will be removed in a future release. Please use SET PASSWORD FOR = '' instead

If you see this warning your can solve it just by removing:

SET PASSWORD FOR root@localhost=PASSWORD('1234');

复制代码

SET PASSWORD FOR root@localhost='';

复制代码

It seems that most DB tools are not updated with last changes and still produce old format queries

MySQL remove root password

If you want to remove the password from your root account in MySQL you can:

login in MySQL or by using a tool

mysql -u root -p

复制代码

and run this command:

SET PASSWORD FOR root@localhost=PASSWORD('');

复制代码

MySQL set new root password

As the previous section if you want to change your root password you can do it by running:

after MySQL 5.7.6:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPass';

复制代码

prior MySQL 5.7.5:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newPass');

复制代码

This way you will reset only the root password. If your forgot your root password than you can check next section.

Windows Resetting the Root Password

For this solution you will need administrative rights:

Stop the MySQL server(service)

Create new text file - C:\mysqlResetRoot.txt

Add this line(for earlier version use - see prevoius section):

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPass';

复制代码

Open Command Prompt

start menu, type cmd and enter

WINDOWS+R and type cmd

Go to your MySQL installation folder:

cd "C:\Program Files\MySQL\MySQL Server 5.7\bin

复制代码

Start MySQL with this command:

mysqld --init-file=C:\\mysqlResetRoot.txt

复制代码

Ubuntu Resetting the Root Password

For Ubuntu and Linux Mint you can do these steps:

Open terminal

Login with the user running the MySQL service

Stop the MySQL server by

sudo systemctl stop mysql

复制代码

for older versions of Ubuntu you can use:

sudo /etc/init.d/mysql stop

复制代码

or

service mysqld stop

复制代码

Create new text file - /home/user/mysqlResetRoot.txt

Add this line(for earlier version use - see prevoius section):

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPass';

复制代码

Start MySQL with this command:

mysqld --init-file=/home/me/mysqlResetRoot.txt &

复制代码

Reset the user by query

Another option to reset the password of your root account is by update statement. This is a simple update - set which will set new password:.

UPDATE mysql.user

SET authentication_string = PASSWORD('newPass'), password_expired = 'N'

WHERE User = 'root' AND Host = 'localhost';

复制代码

Finally reload the table grants by:

FLUSH PRIVILEGES;

复制代码

Reset password from MySQL Workbench

Open MySQL Workbench

Connect to your database

Sidebar

Management

User and Privileges

Select the user - root

Type a new password to reset it

Apply

Reference

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值