Mysql重置root用户密码

 

官方文档:https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html  B.6.3.2.3 Resetting the Root Password: Generic Instructions

 

--skip-grant-tables

跳过权限表的认证,任意用户可进入mysql

可配合--skip-networking参数 让只有本地服务器才有登录的权限

 

--跳过权限管理表  加入--skip-grant-tables 启动数据库,任意用户都可以登录数据库(需要重启数据库)

--关闭数据
[root@hostmysql-m ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]

--启动数据库,跳过权限表校验,并禁止远程连接
[root@hostmysql-m ~]# service mysqld start  --skip-grant-tables --skip-networking
Starting mysqld:                                           [  OK  ]

--以任意用户进入数据库
[root@hostmysql-m ~]# mysql -uxxx -pyyy  
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> select host,user,authentication_string from mysql.user;
+--------------+---------------+-------------------------------------------+
| host         | user          | authentication_string                     |
+--------------+---------------+-------------------------------------------+
| localhost    | root          | *CDAD5CEAFXXXF3D5A3AABF5680121FE3548B3E90 |
| localhost    | mysql.session | *THISISNOTXXXLIDPASSWORDTHATCANBEUSEDHERE |
| localhost    | mysql.sys     | *THISISNOTXXXLIDPASSWORDTHATCANBEUSEDHERE |
| localhost    | bkpuser       | *485CE31BAXXXA48CC047659E110DF200F361CD4E |
| 192.168.56.% | repl          | *7B502777DXXX69164B56BC2B92867F4B47321BA8 |
| %            | flyremote     | *AECCE7346XXX9A5F39688386BF6F85E43C3F169C |
| localhost    |               | *256D7F2A9XXX363EBDADEF5515B74B2B318746FC |
|              | flylocal      | *566AC8467XXXAE79E247AE75B0A770E9B97D9FB0 |
|              |               | *AE1628366XXX3D1D98A4C9D60450A508B8C56F3F |
| 192.168.56.% | usergrant     | *16C54E358XXXB93F32A4F56CD392853E0C646CF1 |
+--------------+---------------+-------------------------------------------+
10 rows in set (0.00 sec)

--更改root用户密码,并刷新权限
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed


mysql>  update user set authentication_string=password("xxxxxx") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


--重启数据库
[root@hostmysql-m ~]# service mysqld restart  
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]


登录成功
[root@hostmysql-m ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> 

 

你可能感兴趣的:(Mysql,基本管理,Mysql—基础功能学习)