mysql5.7修改密码
mysql5.7修改密码
为了提高安全性,mysql5.7中 user 表的 password 被 authentication_string 字段所取代,下面简绍几种修改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]$
修改其他用户示例:
mysql> create database db_test; Query OK, 1 row affected (0.35 sec) mysql> create user 'test_u'@'%' identified by 'kkSWhEpMVZ1xfaebJsRS'; Query OK, 0 rows affected (0.06 sec) mysql> grant select,insert,delete,update on db_test.* to 'test_u'@'%' ; Query OK, 0 rows affected (0.00 sec) -- 测试新建的账号 [root@db134 ~]# mysql -h 192.168.142.134 -utest_u -p'kkSWhEpMVZ1xfaebJsRS' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | db_test | +--------------------+ 2 rows in set (0.00 sec) -- 假设该用户忘记密码 -- 用管理员账号登录操作 mysql> select user,host,authentication_string from mysql.user; +-----------+-----------+-------------------------------------------+ | user | host | authentication_string | +-----------+-----------+-------------------------------------------+ | root | localhost | *9EF2DB3EB868F2BF2AF1F8DD00185B23390E20A3 | | mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | test_u | % | *240FADB0A594DB97220A0F354CF891C0EF9F00D4 | +-----------+-----------+-------------------------------------------+ 3 rows in set (0.00 sec) mysql> alter user 'test_u'@'%' identified by 'kkSWhEpMVZ1xfaebJsHK'; Query OK, 0 rows affected (0.01 sec) -- 用新密码验证登录 [root@db134 ~]# mysql -h 192.168.142.134 -utest_u -p'kkSWhEpMVZ1xfaebJsHK' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 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 [root@db134 ~]# -- 其他两种方法均可 mysql> set password for 'test_u'@'%'=password('kkSWhEpMVZ1xfaebJsXY'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> update mysql.user set authentication_string=password('kkSWhEpMVZ1xfaebJsHG') where user='test_u' and Host = '%'; -- 这个操作,必须执行flush privileges;才能生效 Query OK, 1 row affected, 1 warning (0.08 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
2018-05-24 centos7.2安装完成的基本操作
2018-05-24 root登陆欢迎界面设置
2018-05-24 Linux truncate的使用方法介绍
2018-05-24 libmysqlclient.so.18: cannot open shared object file