连接mysql提示ERROR 1045 (28000),,grant语法

数据库 来源:qq_31737339 7℃ 0评论
[root@VM_111_8_centos shijiu]# mysql -uroot -proot
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

[root@VM_111_8_centos shijiu]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 88
Server version: 5.6.32 MySQL Community Server (GPL)

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> 

问题描述:
直接用mysql -uroot -proot连接数据库提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES),查询结果是权限的问题,但具体怎么回事不知道,只知道用grant命令可以搞定,也就是这句话:

grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;

在官方文档查询grant用法如下:

GRANT 
    priv_type [(column_list)]

    ON object_type/ priv_leve
    TO user
    [REQUIRE ...]
    [WITH GRANT OPTION];
GRANT 

object_type 可以是:TABLE | FUNCTION | PROCEDURE
priv_level为: * , . , db_name.*, db_name.tbl_name, tbl_name,db_name.routine_name

grant命令大概的意思就是给什么东西什么权限

grant 权限 on 对象 to 用户 [WITH GRANT OPTION];