在创建MySQL用户时,选择登录主机为“%”,意思为所有主机均可以连接。

命令如下: grant all privileges on \*.\* to 'kevin'@'%' identified by 'password' with grant option;

创建完成后,登录发现提示如下错误: ERROR 1045 (28000): Access denied for user 'kevin'@'localhost' (using password: YES)

从逻辑上说,%代表所有主机,为什么使用“localhost”就是不行呢?或者也有一种可能性,“%”不包括“localhost”主机,而创建连接时使用到了“localhost”。

新增用户@localhost: grant all privileges on \*.\* to 'kevin'@'localhost' identified by 'password' with grant option;

刷新权限,登录成功。 flush privileges;