How to check the database account password in linux, how to check the user's password in mysql under linux

How to query the user's password in mysql under linux

View users

There is no direct SQL statement to view the user, but to enter the user table of the mysql database (this mysql library and user table are both there from the beginning), directly use select * from user; to see what users are there

use mysql;

select * from user;

The user password is encrypted and cannot be read.

If you forget the mysql password, you can reset the password. How to reset the password: Method 1:

Pause the mysql service

[root@localhost ~]# /etc/init.d/mysqld stop

Shutting down MySQL. [OK]

Skip grant table authorization, enter safe mode, and run in the background

[root@localhost ~]# mysqld_safe --skip-grant-tables &

[1] 5261

[root@localhost ~]# 180729 17:38:21 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.

180729 17:38:21 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@localhost ~]# jobs

[1]+  Running                 mysqld_safe --skip-grant-tables &

Enter safe mode to change password

[root@localhost ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.22-log Source distribution

Copyright (c) 2000, 2011, 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> use mysql;

Database changed

mysql> update user set Password=password('666666')where user='root';

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye

重启mysql服务,尝试用新密码登录

[root@localhost ~]# /etc/init.d/mysqld restart

Shutting down MySQL.180729 17:44:25 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended

[确定]

Starting MySQL..                                           [确定]

[1]+  Done                    mysqld_safe --skip-grant-tables

[root@localhost ~]# mysql -uroot -p666666

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.22-log Source distribution

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

Bye

方法二;

修改配置文件

[root@localhost ~]# vim /etc/my.cnf

26 [mysqld]

27 port            = 3306

28 socket          = /tmp/mysql.sock

29 skip-external-locking

30 skip_grant_tables

[root@localhost ~]# /etc/init.d/mysqld restart

Shutting down MySQL.                                       [确定]

Starting MySQL..                                           [确定]

[root@localhost ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.22-log Source distribution

Copyright (c) 2000, 2011, 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('123123')where user='root';

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4  Changed: 4  Warnings: 0

mysql>  flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye

[root@localhost ~]# mysql -uroot -p123123

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.5.22-log Source distribution

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

Bye

本文由 帝一博客 原创发布。用户在本站发布的原创内容(包括但不仅限于回答、文章和评论),著作权均归用户本人所有。独家文章转载,请联系邮箱:[email protected]。获得授权后,须注明本文地址:

https://www.d1blog.com/article/1162.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324104641&siteId=291194637