mysql5.7.x修改密码

今天访问数据库提示密码错误:

[root@node ~]# mysql -uroot -hlocalhost -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@node ~]# mysql -uroot -hlocalhost -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@node ~]# 

 思来想去,一直想不起密码,最后只有关闭数据库通过添加参数"--skip-grant-tables"来重启启动:

[root@node ~]# /usr/local/mysql/bin/mysqld_safe  --defaults-file=/etc/my.cnf --skip-grant-tables &
[1] 14254
[root@node ~]# 2018-05-06T07:54:11.083543Z mysqld_safe Logging to '/data/mysql/error.log'.
2018-05-06T07:54:11.107761Z mysqld_safe Starting mysqld daemon with databases from /data/mysql

[root@node ~]# ps axu|grep mysql
root      14254  0.5  0.0 113252  1648 pts/0    S    15:54   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables
mysql     15564  1.9 14.5 2265704 272520 pts/0  Sl   15:54   0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --log-error=/data/mysql/error.log --open-files-limit=65535 --pid-file=node.pid --socket=/tmp/mysql.sock --port=3306
root      15606  0.0  0.0 112644   948 pts/0    S+   15:54   0:00 grep --color=auto mysql
[root@node ~]# 

重启MySQL服务后,就开始着手修改密码:

 1 [root@node ~]# mysql
 2 Welcome to the MySQL monitor.  Commands end with ; or \g.
 3 Your MySQL connection id is 2
 4 Server version: 5.7.22-log MySQL Community Server (GPL)
 5 
 6 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
 7 
 8 Oracle is a registered trademark of Oracle Corporation and/or its
 9 affiliates. Other names may be trademarks of their respective
10 owners.
11 
12 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
13 
14 root@db 15:56:  [(none)]> use mysql;
15 Database changed
16 root@db 15:56:  [mysql]> update user set password=password('root@123') where user='root';
17 ERROR 1054 (42S22): Unknown column 'password' in 'field list'
18 root@db 15:57:  [mysql]> 

奇怪了,难道我记错了,后来再一次执行该命令,发现仍然爆出同样的错误,user表中居然没有password这个字段,看了下MySQL版本:5.7.22看来跟5.5 5.6有些不同,进一步查看user表结构:

 1 root@db 15:57:  [mysql]> desc user;
 2 +------------------------+-----------------------------------+------+-----+-----------------------+-------+
 3 | Field                  | Type                              | Null | Key | Default               | Extra |
 4 +------------------------+-----------------------------------+------+-----+-----------------------+-------+
 5 | Host                   | char(60)                          | NO   | PRI |                       |       |
 6 | User                   | char(32)                          | NO   | PRI |                       |       |
 7 | Select_priv            | enum('N','Y')                     | NO   |     | N                     |       |
 8 | Insert_priv            | enum('N','Y')                     | NO   |     | N                     |       |
 9 | Update_priv            | enum('N','Y')                     | NO   |     | N                     |       |
10 | Delete_priv            | enum('N','Y')                     | NO   |     | N                     |       |
11 | Create_priv            | enum('N','Y')                     | NO   |     | N                     |       |
12 | Drop_priv              | enum('N','Y')                     | NO   |     | N                     |       |
13 | Reload_priv            | enum('N','Y')                     | NO   |     | N                     |       |
14 | Shutdown_priv          | enum('N','Y')                     | NO   |     | N                     |       |
15 | Process_priv           | enum('N','Y')                     | NO   |     | N                     |       |
16 | File_priv              | enum('N','Y')                     | NO   |     | N                     |       |
17 | Grant_priv             | enum('N','Y')                     | NO   |     | N                     |       |
18 | References_priv        | enum('N','Y')                     | NO   |     | N                     |       |
19 | Index_priv             | enum('N','Y')                     | NO   |     | N                     |       |
20 | Alter_priv             | enum('N','Y')                     | NO   |     | N                     |       |
21 | Show_db_priv           | enum('N','Y')                     | NO   |     | N                     |       |
22 | Super_priv             | enum('N','Y')                     | NO   |     | N                     |       |
23 | Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N                     |       |
24 | Lock_tables_priv       | enum('N','Y')                     | NO   |     | N                     |       |
25 | Execute_priv           | enum('N','Y')                     | NO   |     | N                     |       |
26 | Repl_slave_priv        | enum('N','Y')                     | NO   |     | N                     |       |
27 | Repl_client_priv       | enum('N','Y')                     | NO   |     | N                     |       |
28 | Create_view_priv       | enum('N','Y')                     | NO   |     | N                     |       |
29 | Show_view_priv         | enum('N','Y')                     | NO   |     | N                     |       |
30 | Create_routine_priv    | enum('N','Y')                     | NO   |     | N                     |       |
31 | Alter_routine_priv     | enum('N','Y')                     | NO   |     | N                     |       |
32 | Create_user_priv       | enum('N','Y')                     | NO   |     | N                     |       |
33 | Event_priv             | enum('N','Y')                     | NO   |     | N                     |       |
34 | Trigger_priv           | enum('N','Y')                     | NO   |     | N                     |       |
35 | Create_tablespace_priv | enum('N','Y')                     | NO   |     | N                     |       |
36 | ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |                       |       |
37 | ssl_cipher             | blob                              | NO   |     | NULL                  |       |
38 | x509_issuer            | blob                              | NO   |     | NULL                  |       |
39 | x509_subject           | blob                              | NO   |     | NULL                  |       |
40 | max_questions          | int(11) unsigned                  | NO   |     | 0                     |       |
41 | max_updates            | int(11) unsigned                  | NO   |     | 0                     |       |
42 | max_connections        | int(11) unsigned                  | NO   |     | 0                     |       |
43 | max_user_connections   | int(11) unsigned                  | NO   |     | 0                     |       |
44 | plugin                 | char(64)                          | NO   |     | mysql_native_password |       |
45 | authentication_string  | text                              | YES  |     | NULL                  |       |
46 | password_expired       | enum('N','Y')                     | NO   |     | N                     |       |
47 | password_last_changed  | timestamp                         | YES  |     | NULL                  |       |
48 | password_lifetime      | smallint(5) unsigned              | YES  |     | NULL                  |       |
49 | account_locked         | enum('N','Y')                     | NO   |     | N                     |       |
50 +------------------------+-----------------------------------+------+-----+-----------------------+-------+
51 45 rows in set (0.00 sec)
52 
53 root@db 16:01:  [mysql]> 
View Code

确实没看到password名字的字段,但是发现一个可疑字段"authentication_string",于是尝试用该字段再执行修改操作:

 1 root@db 16:03:  [mysql]> use mysql;
 2 Database changed
 3 root@db 16:03:  [mysql]> update user set authentication_string=password('root@123') where user='root';
 4 Query OK, 0 rows affected, 1 warning (0.00 sec)
 5 Rows matched: 1  Changed: 0  Warnings: 1
 6 
 7 root@db 16:04:  [mysql]> flush privileges;
 8 Query OK, 0 rows affected (0.39 sec)
 9 
10 root@db 16:04:  [mysql]> exit
11 Bye
View Code

居然可以了,进一步登陆了认证:

 1 [root@node ~]# mysql -uroot -hlocalhost -proot@123
 2 mysql: [Warning] Using a password on the command line interface can be insecure.
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 3
 5 Server version: 5.7.22-log MySQL Community Server (GPL)
 6 
 7 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 root@db 16:04:  [(none)]> show databases;
16 +--------------------+
17 | Database           |
18 +--------------------+
19 | information_schema |
20 | mysql              |
21 | performance_schema |
22 | sys                |
23 +--------------------+
24 4 rows in set (0.00 sec)
25 
26 root@db 16:05:  [(none)]> 
View Code

看来MySQL5.7跟MySQL5.6 MySQL 5.5在密码修改方面也做了改动,作为笔记仅此而已

 

猜你喜欢

转载自www.cnblogs.com/kindnull/p/8998530.html
今日推荐