1. 程式人生 > >mysql root 密碼登入出錯

mysql root 密碼登入出錯

C:\Users\Administrator>mysql -u root -p
Enter password: ******

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

解決方法:

1.檢視資料庫mysql 下的user表

mysql>use mysql

mysql> select Host,User,Password,password_expired from user;

+-----------+------+----------+------------------+
| Host      | User | Password | password_expired |
+-----------+------+----------+------------------+
| localhost | root |          | Y                |
| 127.0.0.1 | root |          | N                |
| ::1       | root |          | N                |
| localhost |      |          | N                |

+-----------+------+----------+------------------+

2.可以看到root使用者沒有密碼,為root設定密碼;

mysql> update user set password=PASSWORD('888888') where Host='localhost' and User='root';
Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

3.再檢視user表的Password欄位:

mysql> select Host,User,Password,password_expired from user;
+-----------+------+-------------------------------------------+----------------
--+
| Host      | User | Password                                  | password_expire
d |
+-----------+------+-------------------------------------------+----------------
--+
| localhost | root | *DA28842831B3C40F4BC1D3C76CF9AD8CBFDAE1CB | Y
  |
| 127.0.0.1 | root |                                           | N
  |
| ::1       | root |                                           | N
  |
| localhost |      |                                           | N
  |
+-----------+------+-------------------------------------------+------------------+

4.再載入許可權表,退出,

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql>quit

5.重新登入:

C:\Users\Administrator>mysql -u root -p

Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.6.11
Copyright (c) 2000, 2017, 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>