欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

如何查看MySQL连接的root密码

程序员文章站 2023-12-05 21:01:10
本文给大家分享的是查看mysql连接的root密码的方法,下面话不多说来来看正文: 1.首先我们进到mysql的bin目录下 ➜ cd /usr/...

本文给大家分享的是查看mysql连接的root密码的方法,下面话不多说来来看正文:

1.首先我们进到mysql的bin目录下

➜ cd /usr/local/mysql/bin

2.切换成root身份

➜ bin sudo su

3.跨过权限的验证

sh-3.2# ./mysqld_safe --skip-grant-tables &
[1] 9451
sh-3.2# 2017-01-03t15:40:10.6nz mysqld_safe logging to '/usr/local/mysql/data/yzydemacbook-pro.local.err'.
2017-01-03t15:40:10.6nz mysqld_safe starting mysqld daemon with databases from /usr/local/mysql/data

4.以root身份登录mysql

./mysql -uroot
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 2
server version: 5.7.12 mysql community server (gpl)

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.

5.选择mysql数据库

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

6.显示mysql数据库下的表

mysql> show tables;
+---------------------------+
| tables_in_mysql   |
+---------------------------+
| columns_priv    |
| db      |
| engine_cost    |
| event      |
| func      |
| general_log    |
| gtid_executed    |
| help_category    |
| help_keyword    |
| help_relation    |
| help_topic    |
| innodb_index_stats  |
| innodb_table_stats  |
| ndb_binlog_index   |
| plugin     |
| proc      |
| procs_priv    |
| proxies_priv    |
| server_cost    |
| servers     |
| slave_master_info   |
| slave_relay_log_info  |
| slave_worker_info   |
| slow_log     |
| tables_priv    |
| time_zone     |
| time_zone_leap_second  |
| time_zone_name   |
| time_zone_transition  |
| time_zone_transition_type |
| user      |
+---------------------------+
31 rows in set (0.00 sec)

7.很明显我们需要的密码是存在user这个表下的,所以我们直接看user的表结构是怎么样的

mysql> show columns from user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| field     | type        | null | key | default    | extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| host     | char(60)       | no | pri |      |  |
| user     | char(32)       | no | pri |      |  |
| select_priv   | enum('n','y')      | no |  | n      |  |
| insert_priv   | enum('n','y')      | no |  | n      |  |
| update_priv   | enum('n','y')      | no |  | n      |  |
| delete_priv   | enum('n','y')      | no |  | n      |  |
| create_priv   | enum('n','y')      | no |  | n      |  |
| drop_priv    | enum('n','y')      | no |  | n      |  |
| reload_priv   | enum('n','y')      | no |  | n      |  |
| shutdown_priv   | enum('n','y')      | no |  | n      |  |
| process_priv   | enum('n','y')      | no |  | n      |  |
| file_priv    | enum('n','y')      | no |  | n      |  |
| grant_priv    | enum('n','y')      | no |  | n      |  |
| references_priv  | enum('n','y')      | no |  | n      |  |
| index_priv    | enum('n','y')      | no |  | n      |  |
| alter_priv    | enum('n','y')      | no |  | n      |  |
| show_db_priv   | enum('n','y')      | no |  | n      |  |
| super_priv    | enum('n','y')      | no |  | n      |  |
| create_tmp_table_priv | enum('n','y')      | no |  | n      |  |
| lock_tables_priv  | enum('n','y')      | no |  | n      |  |
| execute_priv   | enum('n','y')      | no |  | n      |  |
| repl_slave_priv  | enum('n','y')      | no |  | n      |  |
| repl_client_priv  | enum('n','y')      | no |  | n      |  |
| create_view_priv  | enum('n','y')      | no |  | n      |  |
| show_view_priv   | enum('n','y')      | no |  | n      |  |
| create_routine_priv | enum('n','y')      | no |  | n      |  |
| alter_routine_priv  | enum('n','y')      | no |  | n      |  |
| create_user_priv  | enum('n','y')      | no |  | n      |  |
| event_priv    | enum('n','y')      | no |  | n      |  |
| trigger_priv   | enum('n','y')      | no |  | n      |  |
| create_tablespace_priv | enum('n','y')      | no |  | n      |  |
| ssl_type    | enum('','any','x509','specified') | no |  |      |  |
| ssl_cipher    | blob        | no |  | null     |  |
| x509_issuer   | blob        | no |  | null     |  |
| x509_subject   | blob        | no |  | null     |  |
| max_questions   | int(11) unsigned     | no |  | 0      |  |
| max_updates   | int(11) unsigned     | no |  | 0      |  |
| max_connections  | int(11) unsigned     | no |  | 0      |  |
| max_user_connections | int(11) unsigned     | no |  | 0      |  |
| plugin     | char(64)       | no |  | mysql_native_password |  |
| authentication_string | text        | yes |  | null     |  |
| password_expired  | enum('n','y')      | no |  | n      |  |
| password_last_changed | timestamp       | yes |  | null     |  |
| password_lifetime  | smallint(5) unsigned    | yes |  | null     |  |
| account_locked   | enum('n','y')      | no |  | n      |  |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.02 sec)

8.表的内容比较多,但是我们很容易就发现,密码其实是存在authentication_string字段下的,那我们就可以直接读user内容为root的密码了

mysql> select authentication_string from user where user='root';
+-------------------------------------------+
| authentication_string      |
+-------------------------------------------+
| *781d25322166db7ff99ba4a1fa5ed30439a60dde |
+-------------------------------------------+
1 row in set (0.01 sec)

ok,那我们拿着这个密码到navicat试试看

如何查看MySQL连接的root密码 

总结

好了,以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。