mysql5.7修改密码
为了提高安全性 mysql5.7中 user 表的 password 被 authentication_string 字段所取代,下面简绍几种mysql5.7下修改root密码的方法(其他用户也大同小异)。
法一:
mysql> alter user 'root'@'localhost' identified by 'cy7m0ypu8CpLFperzI45';
法二:
mysql> set password for 'root'@'localhost'=password('cy7m0ypu8CpLFperzI45');
法三:
mysql> update mysql.user set authentication_string=password('cy7m0ypu8CpLFperzI45') where user='root' and Host = 'localhost';
-- 记得最后要刷新权限 mysql> flush privileges;
具体示例:
[mysql@db134 application]$ /data/mysql/application/mysql/bin/mysql -uroot -p -h localhost --socket=/data/mysql/percona_server_new/run/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.17-13-log Copyright (c) 2009-2016 Percona LLC and/or its affiliates 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. mysql> set global validate_password_policy=LOW; Query OK, 0 rows affected (0.00 sec) mysql> set password for 'root'@'localhost'=password('cy7m0ypu8CpLFperzI45'); Query OK, 0 rows affected, 1 warning (0.08 sec) mysql> alter user 'root'@'localhost' identified by 'cy7m0ypu8CpLFperzI45'; Query OK, 0 rows affected (0.01 sec) mysql> update mysql.user set authentication_string=password('cy7m0ypu8CpLFperzI45') where user='root' and Host = 'localhost'; Query OK, 0 rows affected, 1 warning (0.05 sec) Rows matched: 1 Changed: 0 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) -- 验证登录 [mysql@db134 application]$ /data/mysql/application/mysql/bin/mysql -uroot -p -h localhost --socket=/data/mysql/percona_server_new/run/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.17-13-log Percona Server (GPL), Release 13, Revision fd33d43 Copyright (c) 2009-2016 Percona LLC and/or its affiliates 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. mysql> exit Bye [mysql@db134 application]$