本文共 2245 字,大约阅读时间需要 7 分钟。
[root@localhost ~]# cat /etc/my.cnf 注:在配置文件的【mysqld】下添加一行
[mysqld]skip-grant-tables[root@localhost ~]# systemctl restart mysqld.service #重启服务
[root@localhost ~]# mysql -u root -p Enter password: 注:回车 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.23-log Source distributionCopyright (c) 2000, 2018, 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;
mysql> show tables; 注:查看MySQL下的表,更新user即可
+---------------------------+ | 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 | +---------------------------+mysql> update user set authentication_string=password('123.com') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1注:密码列不再是password,而是authentication_string
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)mysql> quit
注:将/etc/my.cnf下的skip-grant-tables删掉再次重启。
[root@localhost ~]# mysql -u root -p123.com 修改成功
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 3 Server version: 5.7.23-log Source distributionCopyright (c) 2000, 2018, 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> 展现你的技术吧!
转载地址:http://nzxvb.baihongyu.com/