mysql登录报错ERROR 1045 (28000的解决方法
2015-08-04 16:54
573 查看
问题描述:
mysql -u root -p命令登录MySQL,提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决办法:
information_schema 库的USER_PRIVILEGES 表中 没有给 'root'@'localhost' 赋权。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*7CF1EF598B5B0FC97DAD7C8051A25DC0CE8A9AD9' ;
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for root@localhost;
+----------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*7CF1EF598B5B0FC97DAD7C8051A25DC0CE8A9AD9' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> flush PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
注意:赋权中的 PASSWORD '*7CF1EF598B5B0FC97DAD7C8051A25DC0CE8A9AD9' ; 是 root的密码加密后的字符串。 可以在 mysql库中的 user 表中查到。
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from user;
问题分析:
通过 mysql -u root -p -h 127.0.0.1 可以登录,但是 mysql -u root -p 就报错。
查看information_schema 库的 USER_PRIVILEGES; 表,发现'root'@'localhost' 没有权限。 执行
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*7CF1EF598B5B0FC97DAD7C8051A25DC0CE8A9AD9' ; 赋权后,
mysql> select * from USER_PRIVILEGES ;
+--------------------------------+---------------+-------------------------+--------------+
| GRANTEE | TABLE_CATALOG | PRIVILEGE_TYPE | IS_GRANTABLE |
+--------------------------------+---------------+-------------------------+--------------+
| 'root'@'localhost.localdomain' | def | SELECT | YES |
| 'root'@'localhost.localdomain' | def | INSERT | YES |
| 'root'@'localhost.localdomain' | def | UPDATE | YES |
| 'root'@'localhost.localdomain' | def | DELETE | YES |
| 'root'@'localhost.localdomain' | def | CREATE | YES |
| 'root'@'localhost.localdomain' | def | DROP | YES |
| 'root'@'localhost.localdomain' | def | RELOAD | YES |
| 'root'@'localhost.localdomain' | def | SHUTDOWN | YES |
| 'root'@'localhost.localdomain' | def | PROCESS | YES |
| 'root'@'localhost.localdomain' | def | FILE | YES |
| 'root'@'localhost.localdomain' | def | REFERENCES | YES |
| 'root'@'localhost.localdomain' | def | INDEX | YES |
| 'root'@'localhost.localdomain' | def | ALTER | YES |
| 'root'@'localhost.localdomain' | def | SHOW DATABASES | YES |
| 'root'@'localhost.localdomain' | def | SUPER | YES |
| 'root'@'localhost.localdomain' | def | CREATE TEMPORARY TABLES | YES |
| 'root'@'localhost.localdomain' | def | LOCK TABLES | YES |
| 'root'@'localhost.localdomain' | def | EXECUTE | YES |
| 'root'@'localhost.localdomain' | def | REPLICATION SLAVE | YES |
| 'root'@'localhost.localdomain' | def | REPLICATION CLIENT | YES |
| 'root'@'localhost.localdomain' | def | CREATE VIEW | YES |
| 'root'@'localhost.localdomain' | def | SHOW VIEW | YES |
| 'root'@'localhost.localdomain' | def | CREATE ROUTINE | YES |
| 'root'@'localhost.localdomain' | def | ALTER ROUTINE | YES |
| 'root'@'localhost.localdomain' | def | CREATE USER | YES |
| 'root'@'localhost.localdomain' | def | EVENT | YES |
| 'root'@'localhost.localdomain' | def | TRIGGER | YES |
| 'root'@'localhost.localdomain' | def | CREATE TABLESPACE | YES |
| 'root'@'127.0.0.1' | def | SELECT | YES |
| 'root'@'127.0.0.1' | def | INSERT | YES |
| 'root'@'127.0.0.1' | def | UPDATE | YES |
| 'root'@'127.0.0.1' | def | DELETE | YES |
| 'root'@'127.0.0.1' | def | CREATE | YES |
| 'root'@'127.0.0.1' | def | DROP | YES |
| 'root'@'127.0.0.1' | def | RELOAD | YES |
| 'root'@'127.0.0.1' | def | SHUTDOWN | YES |
| 'root'@'127.0.0.1' | def | PROCESS | YES |
| 'root'@'127.0.0.1' | def | FILE | YES |
| 'root'@'127.0.0.1' | def | REFERENCES | YES |
| 'root'@'127.0.0.1' | def | INDEX | YES |
| 'root'@'127.0.0.1' | def | ALTER | YES |
| 'root'@'127.0.0.1' | def | SHOW DATABASES | YES |
| 'root'@'127.0.0.1' | def | SUPER | YES |
| 'root'@'127.0.0.1' | def | CREATE TEMPORARY TABLES | YES |
| 'root'@'127.0.0.1' | def | LOCK TABLES | YES |
| 'root'@'127.0.0.1' | def | EXECUTE | YES |
| 'root'@'127.0.0.1' | def | REPLICATION SLAVE | YES |
| 'root'@'127.0.0.1' | def | REPLICATION CLIENT | YES |
| 'root'@'127.0.0.1' | def | CREATE VIEW | YES |
| 'root'@'127.0.0.1' | def | SHOW VIEW | YES |
| 'root'@'127.0.0.1' | def | CREATE ROUTINE | YES |
| 'root'@'127.0.0.1' | def | ALTER ROUTINE | YES |
| 'root'@'127.0.0.1' | def | CREATE USER | YES |
| 'root'@'127.0.0.1' | def | EVENT | YES |
| 'root'@'127.0.0.1' | def | TRIGGER | YES |
| 'root'@'127.0.0.1' | def | CREATE TABLESPACE | YES |
| 'root'@'::1' | def | SELECT | YES |
| 'root'@'::1' | def | INSERT | YES |
| 'root'@'::1' | def | UPDATE | YES |
| 'root'@'::1' | def | DELETE | YES |
| 'root'@'::1' | def | CREATE | YES |
| 'root'@'::1' | def | DROP | YES |
| 'root'@'::1' | def | RELOAD | YES |
| 'root'@'::1' | def | SHUTDOWN | YES |
| 'root'@'::1' | def | PROCESS | YES |
| 'root'@'::1' | def | FILE | YES |
| 'root'@'::1' | def | REFERENCES | YES |
| 'root'@'::1' | def | INDEX | YES |
| 'root'@'::1' | def | ALTER | YES |
| 'root'@'::1' | def | SHOW DATABASES | YES |
| 'root'@'::1' | def | SUPER | YES |
| 'root'@'::1' | def | CREATE TEMPORARY TABLES | YES |
| 'root'@'::1' | def | LOCK TABLES | YES |
| 'root'@'::1' | def | EXECUTE | YES |
| 'root'@'::1' | def | REPLICATION SLAVE | YES |
| 'root'@'::1' | def | REPLICATION CLIENT | YES |
| 'root'@'::1' | def | CREATE VIEW | YES |
| 'root'@'::1' | def | SHOW VIEW | YES |
| 'root'@'::1' | def | CREATE ROUTINE | YES |
| 'root'@'::1' | def | ALTER ROUTINE | YES |
| 'root'@'::1' | def | CREATE USER | YES |
| 'root'@'::1' | def | EVENT | YES |
| 'root'@'::1' | def | TRIGGER | YES |
| 'root'@'::1' | def | CREATE TABLESPACE | YES |
mysql -u root -p命令登录MySQL,提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决办法:
information_schema 库的USER_PRIVILEGES 表中 没有给 'root'@'localhost' 赋权。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*7CF1EF598B5B0FC97DAD7C8051A25DC0CE8A9AD9' ;
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for root@localhost;
+----------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*7CF1EF598B5B0FC97DAD7C8051A25DC0CE8A9AD9' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> flush PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
注意:赋权中的 PASSWORD '*7CF1EF598B5B0FC97DAD7C8051A25DC0CE8A9AD9' ; 是 root的密码加密后的字符串。 可以在 mysql库中的 user 表中查到。
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from user;
问题分析:
通过 mysql -u root -p -h 127.0.0.1 可以登录,但是 mysql -u root -p 就报错。
查看information_schema 库的 USER_PRIVILEGES; 表,发现'root'@'localhost' 没有权限。 执行
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*7CF1EF598B5B0FC97DAD7C8051A25DC0CE8A9AD9' ; 赋权后,
mysql> select * from USER_PRIVILEGES ;
+--------------------------------+---------------+-------------------------+--------------+
| GRANTEE | TABLE_CATALOG | PRIVILEGE_TYPE | IS_GRANTABLE |
+--------------------------------+---------------+-------------------------+--------------+
| 'root'@'localhost.localdomain' | def | SELECT | YES |
| 'root'@'localhost.localdomain' | def | INSERT | YES |
| 'root'@'localhost.localdomain' | def | UPDATE | YES |
| 'root'@'localhost.localdomain' | def | DELETE | YES |
| 'root'@'localhost.localdomain' | def | CREATE | YES |
| 'root'@'localhost.localdomain' | def | DROP | YES |
| 'root'@'localhost.localdomain' | def | RELOAD | YES |
| 'root'@'localhost.localdomain' | def | SHUTDOWN | YES |
| 'root'@'localhost.localdomain' | def | PROCESS | YES |
| 'root'@'localhost.localdomain' | def | FILE | YES |
| 'root'@'localhost.localdomain' | def | REFERENCES | YES |
| 'root'@'localhost.localdomain' | def | INDEX | YES |
| 'root'@'localhost.localdomain' | def | ALTER | YES |
| 'root'@'localhost.localdomain' | def | SHOW DATABASES | YES |
| 'root'@'localhost.localdomain' | def | SUPER | YES |
| 'root'@'localhost.localdomain' | def | CREATE TEMPORARY TABLES | YES |
| 'root'@'localhost.localdomain' | def | LOCK TABLES | YES |
| 'root'@'localhost.localdomain' | def | EXECUTE | YES |
| 'root'@'localhost.localdomain' | def | REPLICATION SLAVE | YES |
| 'root'@'localhost.localdomain' | def | REPLICATION CLIENT | YES |
| 'root'@'localhost.localdomain' | def | CREATE VIEW | YES |
| 'root'@'localhost.localdomain' | def | SHOW VIEW | YES |
| 'root'@'localhost.localdomain' | def | CREATE ROUTINE | YES |
| 'root'@'localhost.localdomain' | def | ALTER ROUTINE | YES |
| 'root'@'localhost.localdomain' | def | CREATE USER | YES |
| 'root'@'localhost.localdomain' | def | EVENT | YES |
| 'root'@'localhost.localdomain' | def | TRIGGER | YES |
| 'root'@'localhost.localdomain' | def | CREATE TABLESPACE | YES |
| 'root'@'127.0.0.1' | def | SELECT | YES |
| 'root'@'127.0.0.1' | def | INSERT | YES |
| 'root'@'127.0.0.1' | def | UPDATE | YES |
| 'root'@'127.0.0.1' | def | DELETE | YES |
| 'root'@'127.0.0.1' | def | CREATE | YES |
| 'root'@'127.0.0.1' | def | DROP | YES |
| 'root'@'127.0.0.1' | def | RELOAD | YES |
| 'root'@'127.0.0.1' | def | SHUTDOWN | YES |
| 'root'@'127.0.0.1' | def | PROCESS | YES |
| 'root'@'127.0.0.1' | def | FILE | YES |
| 'root'@'127.0.0.1' | def | REFERENCES | YES |
| 'root'@'127.0.0.1' | def | INDEX | YES |
| 'root'@'127.0.0.1' | def | ALTER | YES |
| 'root'@'127.0.0.1' | def | SHOW DATABASES | YES |
| 'root'@'127.0.0.1' | def | SUPER | YES |
| 'root'@'127.0.0.1' | def | CREATE TEMPORARY TABLES | YES |
| 'root'@'127.0.0.1' | def | LOCK TABLES | YES |
| 'root'@'127.0.0.1' | def | EXECUTE | YES |
| 'root'@'127.0.0.1' | def | REPLICATION SLAVE | YES |
| 'root'@'127.0.0.1' | def | REPLICATION CLIENT | YES |
| 'root'@'127.0.0.1' | def | CREATE VIEW | YES |
| 'root'@'127.0.0.1' | def | SHOW VIEW | YES |
| 'root'@'127.0.0.1' | def | CREATE ROUTINE | YES |
| 'root'@'127.0.0.1' | def | ALTER ROUTINE | YES |
| 'root'@'127.0.0.1' | def | CREATE USER | YES |
| 'root'@'127.0.0.1' | def | EVENT | YES |
| 'root'@'127.0.0.1' | def | TRIGGER | YES |
| 'root'@'127.0.0.1' | def | CREATE TABLESPACE | YES |
| 'root'@'::1' | def | SELECT | YES |
| 'root'@'::1' | def | INSERT | YES |
| 'root'@'::1' | def | UPDATE | YES |
| 'root'@'::1' | def | DELETE | YES |
| 'root'@'::1' | def | CREATE | YES |
| 'root'@'::1' | def | DROP | YES |
| 'root'@'::1' | def | RELOAD | YES |
| 'root'@'::1' | def | SHUTDOWN | YES |
| 'root'@'::1' | def | PROCESS | YES |
| 'root'@'::1' | def | FILE | YES |
| 'root'@'::1' | def | REFERENCES | YES |
| 'root'@'::1' | def | INDEX | YES |
| 'root'@'::1' | def | ALTER | YES |
| 'root'@'::1' | def | SHOW DATABASES | YES |
| 'root'@'::1' | def | SUPER | YES |
| 'root'@'::1' | def | CREATE TEMPORARY TABLES | YES |
| 'root'@'::1' | def | LOCK TABLES | YES |
| 'root'@'::1' | def | EXECUTE | YES |
| 'root'@'::1' | def | REPLICATION SLAVE | YES |
| 'root'@'::1' | def | REPLICATION CLIENT | YES |
| 'root'@'::1' | def | CREATE VIEW | YES |
| 'root'@'::1' | def | SHOW VIEW | YES |
| 'root'@'::1' | def | CREATE ROUTINE | YES |
| 'root'@'::1' | def | ALTER ROUTINE | YES |
| 'root'@'::1' | def | CREATE USER | YES |
| 'root'@'::1' | def | EVENT | YES |
| 'root'@'::1' | def | TRIGGER | YES |
| 'root'@'::1' | def | CREATE TABLESPACE | YES |
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- 访问Nginx发生SSL connection error的一种情况
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜