mysql this account_修改mysql账户密码

Summary: in this tutorial you will learn how to change or reset password for MySQL account in various ways by using the UPDATE, SET PASSWORD and GRANTstatements.

Before changing the password, there are some points that you should consider:Which user do you want to change the password?

What host, which the user connects to, you want to change the password?

Have you been aware of the related applications that are currently using the MySQL account whose password is being changed?If you change the password without proper planning, those applications will lose the connection to the database and stop functioning properly.

MySQL provides several statements that you can use to change or reset password of a MySQL account including UPDATEstatement, SET PASSWORD statement and GRANT USAGE statement.

MySQL changing password using UPDATE statement

The first way to change the password is to use the UPDATEstatement to update the Userand Hostcolumn of the usertable in the mysqldatabase. After executing the UPDATEstatement, you need to execute the FLUSH PRIVILEGES statement to reload privileges from the grant table in the mysqldatabase.

Suppose you want to change the password for OutOfMemoryuser that connect from the  OutOfMemory.CNhost to Secret1970, you need to execute the following statements:USE mysql; UPDATE user  SET password = PASSWORD('Secret1970') WHERE user = 'OutOfMemory' AND        host = 'OutOfMemory.CN'; FLUSH PRIVILEGES;

It is important to note that we’ve used the PASSWORD()function to encrypt the plain text password. The following example demonstrates how the PASSWORD() function encrypts a plain text password.SELECT PASSWORD('Secret1970') AS encrypt_password

*16A54B5EE15C823362FAE7F64409A8F8C8501DD6

MySQL changing password using SET PASSWORD statement

The second way to change the password is by using the SET PASSWORD statement. You use the MySQL account in  user@host format to update the password. If you need to change password for other accounts, you need to have at least UPDATEprivilege. You don’t need to execute the FLUSH PRVILILEGES statement to reload privileges from grant table.

The following statement change password of OutOfMemoryaccount by using the SET PASSWORD statement.SET PASSWORD FOR 'mysqltutorail'@'OutOfMemory.CN' = PASSWORD('Secret1970')

MySQL changing password using GRANT USAGE statement

The third way to change the password is by using the GRANT USAGE statement with the IDENTIFIED BY clause. In this way, you specify the password in plain text instead of the encrypted from.

The following statement changes the password of OutOfMemory account by using the GRANT USAGE statement:GRANT USAGE ON *.* TO OutOfMemory@OutOfMemory.CN IDENTIFIED BY Secret1970

In case you want to reset the MySQL root account’s password, you need to force the MySQL database server to stop and restart without using grant table validation.

In this tutorial, we introduced you to some handy MySQL statements that allows you to change MySQL accounts password.

Related Tutorials

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值