mysql访问被拒绝eventhough授予权限存在

时间:2015-08-11 15:39:29

标签: mysql database mariadb

我已创建用户并授予所有权限,但仍无法使用它连接到sql。有人可以帮忙解决这个问题吗?

接下来的步骤     mysql --user = root mysql;

CREATE USER 'db_user'@'%' IDENTIFIED BY 'password'; 
CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'password'; 
CREATE USER 'db_user'@'hostname' IDENTIFIED BY 'password'; 
GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'%' WITH GRANT OPTION; 
GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'hostname' WITH GRANT OPTION;

当我尝试连接时

mysql -u db_user -ppassword -h 'hostname' 

我收到此错误

ERROR 1045 (28000): Access denied for user 'db_user'@'hostname' (using password: YES)

MariaDB [(none)]> show grants for db_user@'hostname';

GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'hostname' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WITH GRANT OPTION 
1 row in set (0.00 sec)

没有让它连接的缺点是什么?

1 个答案:

答案 0 :(得分:1)

您能再次确认主机名是本地主机的hostname吗?

你能试试吗?

DROP USER 'db_user'@'localhost';
DROP USER 'db_user'@'%';
DROP USER 'db_user'@'hostname';
GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'%' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'hostname' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WITH GRANT OPTION;

mysql -u db_user -ppassword -h `hostname`