MySQL错误1045,“拒绝访问用户'user'@'localhost'(使用密码:是)" [英] MySQL Error 1045, "Access denied for user 'user'@'localhost' (using password: YES)"

查看:468
本文介绍了MySQL错误1045,“拒绝访问用户'user'@'localhost'(使用密码:是)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎被问了很多,但是我找不到确切的答案.

我正在使用MySQL进行一些Webapp测试,并且一开始我使用了'root'用户(使用非空密码).我的root用户可以通过应用程序(通过PHP和Python的Django测试),命令行以及PHPMyAdmin正常运行.

但是,我不想使用root用户,所以我创建了另一个用户,并向该用户授予了所需的数据库所有特权. (我使用PHPMyAdmin登录为'root'来完成此任务).

新用户无法登录MySQL.既不是来自Django应用程序,也不是来自PHPMyAdmin,也不是来自命令行.

我有两种可能的怀疑:

  1. 用户缺少全局特权. (正如我说的,我授予了所有数据库特权,但没有授予任何全局特权);

  2. 用户配置的主机. ('root' mysql.user 表中有四行,用于主机'localhost''my-pc-name ''127.0.0.1'':: 1';而新用户对主机'%')

(我已经仔细检查了密码,因此我确信这不是密码问题.)

解决方案

%表示新用户可以从任何主机访问数据库.

但是,如果您提供了CREATE USER语句,则将更加有用.

此外,请查看下面的MySQL手册,其中解释了为什么用户应同时拥有@'localhost'@'%':

MySQL参考手册-添加用户

This question seem to be asked a lot however I cannot find a definitive answer.

I am making some webapp tests using MySQL, and at the beginning I used the 'root' user (with a non-empty password). My root user is working fine from the apps (tested from PHP and Python's Django), from the command line, and with PHPMyAdmin.

However I don't wanted to use the the root user, so I created another user, and I granted all privileges to the databases that user should need. (I used PHPMyAdmin logged as 'root' for this task).

The new user cannot log in to MySQL. Neither from the Django app, nor PHPMyAdmin, nor the command line.

I have two possible suspicions:

  1. there is a global privilege the user lacks. (As I said, I granted all database privileges, however I have not granted any global privileges);

  2. the user's configured host. ('root' has four lines in the mysql.user table, for hosts 'localhost', 'my-pc-name', '127.0.0.1' and '::1'; while the new user has one line for host '%')

(I have double-checked the password, so I am confident this is not a password problem.)

解决方案

% means that the new user can access the database from any host.

However, if you supplied the CREATE USER statement would be much more useful.

In addition, check MySQL Manual below, where it explains why a user should have both @'localhost' and @'%':

MySQL Reference Manual - Adding Users

这篇关于MySQL错误1045,“拒绝访问用户'user'@'localhost'(使用密码:是)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆