学习mysql时发现登录不上mysql,总是提示:Access denied for user 'root'@'localhost' (using password:YES)。
1>以管理员的身份运行cmd.exe,进入到mysql的bin目录下C:\Program Files\MySQL\mysql-5.7.10-winx64\bin>net stop mysql(停止mysql服务).#MySQL 服务正在停止.#MySQL 服务已成功停止。#MYSQL 启动服务的命令:net start mysql
2>C:\Program Files\MySQL\mysql-5.7.10-winx64\bin>mysqld --skip-grant-tables (你会看到窗口光标在下一行的第一个位置闪烁,这说明已经启动了,不需要管。 )
3>新建一个命令行窗口cmd.exe可不用管理员运行.
4>mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hwl_160111 || mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
5>mysql> use mysql
Database changed
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)
6>mysql> select * from user;
+-----------+-----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+| Host | User | Select_priv | Insert_priv | Update_priv | Delete_priv| Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired | password_last_changed | password_lifetime | account_locked |
重点内容
7>你发现没有password这个字段,仔细看看,authentication_string;
mysql> select authentication_string from mysql.user;
+-------------------------------------------+
| authentication_string |
+-------------------------------------------+
| *3850A8D8B8D396B78359100B96A8D4A19884F930 |
| *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-------------------------------------------+
果然,加密后的密码,那就好办了,想好新密码
mysql> UPDATE mysql.user SET authentication_string=PASSWORD(’新密码’) WHERE User=’root’;mysql> FLUSH PRIVILEGES;
好了,已经OK了。我个人喜好,重启MySQL服务,你可以不照做。现在回去测试重连$ mysql -u root -p$ 新密码$到这里基本ok了。C:\Users\Administrator>mysql -u root -pEnter password: ******Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 7Server version: 5.7.10Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
8>mysql> show databases;ERROR 1820 (HY000):
You must reset your password using ALTER USER statement before executing this statement.
奇怪的发现刚刚设置的密码,又过期了
mysql> SET PASSWORD = PASSWORD('123456');
//重置密码Query OK, 0 rows affected, 1 warning (1.52 sec)
Access denied for user ‘root’@’localhost’ (using password:YES)
最新推荐文章于 2019-06-24 21:22:38 发布