linux下mysql如何查询用户的密码

摘要: linux下mysql如何查询用户的密码,mysql,查询用户,密码,数据库,好用的数据库指南,您值得拥有

linux下mysql如何查询用户的密码

  查看用户

  查看用户并没有直接的SQL语句,而是进入 mysql数据库的user表(这个mysql库和user表都是一开始就有的),直接用 select * from user;来查看有什么用户

  use mysql;

  select * from user;

用户密码是加密状态,是看不了密码。

要是忘记mysql密码可以重置密码,重置密码的方法:

方法一:
暂停mysql服务
[root@localhost ~]# /etc/init.d/mysqld stop
Shutting down MySQL.                                       [确定]
 
跳过grant表授权,进入安全模式,并在后台运行
[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 &
 
进入安全模式修改密码
[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



 

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

网友留言评论

0条评论