0

[转载] MySQL Change a User Password

转自:https://www.cyberciti.biz/faq/mysql-change-user-password/

How to change user password on mysql

Mysql change user password using the following method:

  1. Open the bash shell and connect to the server as root user
  2. mysql -u root -h localhost -p
  3. Run command:
  4. ALTER USER ‘userName’@’localhost’ IDENTIFIED BY ‘New-Password-Here’;

Please note that use mysql.exe on MS-Windows host as follows (first change directory where mysql.exe is located [example: “C:\Program Files\mysql\mysql-5.0.77-win32\bin”]. Let us see examples and syntax in details.

mysql sql command to change a user password

Login as root from the shell:
$ mysql -u root -p
Switch to mysql database (type command at mysql> prompt, do not include string “mysql>”):
mysql> use mysql;
The syntax is as follows for mysql database server version 5.7.5 or older:

For mysql database server version 5.7.6 or newer use the following syntax:

You can also use the following sql syntax:

In this example, change a password for a user called tom:

OR

Sample outputs:

Feel free to replace the values for “tom” (user), “localhost” (hostname), and “foobar” (password) as per your requirements. Finally, type the following command to reload privileges:

Sample outputs:

To exit from mysql> prompt, enter:

User or you can test new password using the following shell syntax:
mysql -u tom -p
When promoted enter new password you set earlier for tom user.

Sample session

Fig.01: Mysql Updating / Changing password (click to enlarge)
Fig.01: Mysql Updating / Changing password (click to enlarge)
打赏作者
miao

miao

发表评论

电子邮件地址不会被公开。