Mysql修改密码的三种方式

一、系统命令

mysqladmin命令修改root密码

rshine@Ubunt14:~$ mysqladmin -uroot -p password "Admin@123456"          # mysqladmin命令修改root密码,“Admin@123456”为修改后的密码
Enter password:                      # 输入旧密码
Warning: Using a password on the command line interface can be insecure.
rshine@Ubunt14:~$
rshine@Ubunt14:~$

二、mysql命令设置新密码

set password for root@"localhost"=password("新密码");

rshine@Ubunt14:~$ mysql -uroot -p              # 旧密码登录MySQL
Enter password:            # 输入旧密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 5.6.33-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password for root@localhost=password("Admin@123456!");                  # mysql set命令修改密码,“Admin@123456!”为修改后的密码
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;                    # 刷新权限
Query OK, 0 rows affected (0.00 sec)

mysql>

三、修改MySQL存储密码字段的值

命令:update mysql.user set password=password("Admin@123456") where user="root" and host="localhost";

rshine@Ubunt14:~$ mysql -uroot -p        # 旧密码登录MySQL
Enter password:           # 输入旧密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 54
Server version: 5.6.33-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> update mysql.user set password=password("Admin@123456") where user="root" and host="localhost";              # update 修改存储密码字段的值
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

mysql> flush privileges;        # 刷新权限
Query OK, 0 rows affected (0.00 sec)

你可能感兴趣的:(Mysql修改密码的三种方式)