简体   繁体   English

启用远程 MySQL 连接:ERROR 1045 (28000): Access denied for user

[英]Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user

MySQL 5.1.31 running on Windows XP. MySQL 5.1.31 在 Windows XP 上运行。

From the local MySQL server (192.168.233.142) I can connect as root as follows:本地MySQL 服务器 (192.168.233.142) 我可以以 root 身份连接,如下所示:

>mysql --host=192.168.233.142 --user=root --password=redacted

From a remote machine (192.168.233.163), I can see that the mysql port is open:远程机器(192.168.233.163),我可以看到mysql端口是开放的:

# telnet 192.168.233.142 3306
Trying 192.168.233.142...
Connected to 192.168.233.142 (192.168.233.142).

But when trying to connect to mysql from the remote machine, I receive:但是当尝试从远程机器连接到 mysql 时,我收到:

# mysql --host=192.168.233.142 --user=root --password=redacted
ERROR 1045 (28000): Access denied for user 'root'@'192.168.233.163' (using password: YES)

I have only 2 entries in mysql.user:我在 mysql.user 中只有 2 个条目:

Host         User     Password
--------------------------------------
localhost    root     *blahblahblah
%            root     [same as above]

What more do I need to do to enable remote access?我还需要做什么才能启用远程访问?

EDIT编辑

As suggested by Paulo below, I tried replacing the mysql.user entry for % with an IP specific entry, so my user table now looks like this:正如下面 Paulo 所建议的,我尝试将 % 的 mysql.user 条目替换为 IP 特定条目,因此我的用户表现在如下所示:

Host             User     Password
------------------------------------------
localhost        root     *blahblahblah
192.168.233.163  root     [same as above]

I then restarted the machine, but the problem persists.然后我重新启动了机器,但问题仍然存在。

You have to put this as root:你必须把它作为根:

GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'IP' IDENTIFIED BY 'PASSWORD' with grant option;

; ;

where IP is the IP you want to allow access, USERNAME is the user you use to connect, and PASSWORD is the relevant password.其中 IP 是您要允许访问的 IP,USERNAME 是您用来连接的用户,PASSWORD 是相关密码。

If you want to allow access from any IP just put % instead of your IP如果您想允许从任何 IP 访问,只需输入%而不是您的 IP

and then you only have to put然后你只需要放

FLUSH PRIVILEGES;

Or restart mysql server and that's it.或者重启mysql服务器,就是这样。

I was getting the same error after granting remote access until I made this:在授予远程访问权限后,我遇到了同样的错误,直到我这样做:

From /etc/mysql/my.cnf/etc/mysql/my.cnf

In newer versions of mysql the location of the file is /etc/mysql/mysql.conf.d/mysqld.cnf在较新版本的 mysql 中,文件的位置是/etc/mysql/mysql.conf.d/mysqld.cnf

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1

(comment this line: bind-address = 127.0.0.1 ) (注释此行: bind-address = 127.0.0.1

Then run service mysql restart .然后运行service mysql restart

By default in MySQL server remote access is disabled.默认情况下,MySQL 服务器远程访问是禁用的。 The process to provide a remote access to user is.为用户提供远程访问的过程是。

  1. Go to my sql bin folder or add it to PATH转到我的 sql bin 文件夹或将其添加到PATH
  2. Login to root by mysql -uroot -proot (or whatever the root password is.)通过mysql -uroot -proot (或任何 root 密码)登录到 root。
  3. On success you will get mysql>成功后你会得到mysql>
  4. Provide grant access all for that user.为该用户提供所有授予访问权限。

GRANT ALL PRIVILEGES ON *.* TO 'username'@'IP' IDENTIFIED BY 'password';

Here IP is IP address for which you want to allow remote access, if we put % any IP address can access remotely.这里的 IP 是您希望允许远程访问的 IP 地址,如果我们输入%任何 IP 地址都可以远程访问。

Example:例子:

C:\Users\UserName> cd C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin

C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin>mysql -uroot -proot

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.27 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.25 sec)

This for a other user.这对于其他用户。

mysql> GRANT ALL PRIVILEGES ON *.* TO 'testUser'@'%' IDENTIFIED BY 'testUser';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Hope this will help希望这会有所帮助

Paulo's help lead me to the solution. Paulo 的帮助使我找到了解决方案。 It was a combination of the following:它是以下内容的组合:

  • the password contained a dollar sign密码包含一个美元符号
  • I was trying to connect from a Linux shell我试图从 Linux shell 连接

The bash shell treats the dollar sign as a special character for expansion to an environment variable, so we need to escape it with a backslash. bash shell 将美元符号视为扩展为环境变量的特殊字符,因此我们需要使用反斜杠对其进行转义。 Incidentally, we don't have to do this in the case where the dollar sign is the final character of the password.顺便说一句,在美元符号是密码的最后一个字符的情况下,我们不必这样做。

As an example, if your password is "pas$word", from Linux bash we must connect as follows:例如,如果您的密码是“pas$word”,则从 Linux bash 我们必须按如下方式连接:

# mysql --host=192.168.233.142 --user=root --password=pas\$word

Do you have a firewall ?你有防火墙吗? make sure that port 3306 is open.确保端口 3306 已打开。

On windows , by default mysql root account is created that is permitted to have access from localhost only unless you have selected the option to enable access from remote machines during installation .在 Windows 上,默认情况下会创建 mysql root 帐户,该帐户仅允许从 localhost 进行访问,除非您在安装期间选择了启用从远程计算机访问的选项。

creating or update the desired user with '%' as hostname .使用 '%' 作为主机名创建或更新所需的用户。

example :例子 :

CREATE USER 'krish'@'%' IDENTIFIED BY 'password';
  1. Try to flush privileges again.再次尝试flush privileges

  2. Try to restart server to reload grants.尝试重新启动服务器以重新加载授权。

  3. Try create a user with host "192.168.233.163".尝试使用主机“192.168.233.163”创建一个用户。 "%" appears to not allow all (it's weird) “%”似乎不允许所有(这很奇怪)

In my case I was trying to connect to a remote mysql server on cent OS.就我而言,我试图连接到 cent OS 上的远程 mysql 服务器。 After going through a lot of solutions (granting all privileges, removing ip bindings,enabling networking) problem was still not getting solved.在经历了很多解决方案(授予所有权限、删除 ip 绑定、启用网络)之后,问题仍然没有得到解决。

As it turned out, while looking into various solutions,I came across iptables, which made me realize mysql port 3306 was not accepting connections.事实证明,在研究各种解决方案时,我遇到了 iptables,这让我意识到 mysql 端口 3306 不接受连接。

Here is a small note on how I checked and resolved this issue.这是关于我如何检查和解决此问题的小说明。

  • Checking if port is accepting connections:检查端口是否接受连接:

    telnet (mysql server ip) [portNo] telnet (mysql 服务器 ip) [portNo]

  • Adding ip table rule to allow connections on the port:添加 ip table 规则以允许端口上的连接:

    iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT

  • Would not recommend this for production environment, but if your iptables are not configured properly, adding the rules might not still solve the issue.不建议将其用于生产环境,但如果您的 iptables 配置不正确,添加规则可能仍无法解决问题。 In that case following should be done:在这种情况下,应执行以下操作:

    service iptables stop服务 iptables 停止

Hope this helps.希望这可以帮助。

如果您使用的是动态 IP,只需授予对 192.168.2.% 的访问权限,因此现在您不必担心每次都授予对您的 IP 地址的访问权限。

I was struggling with remote login to MYSQL for my Amazon EC2 Linux instance.我正在为我的 Amazon EC2 Linux 实例远程登录 MYSQL 而苦苦挣扎。 Found the solution was to make sure my security group included an inbound rule for MySQL port 3306 to include my IP address (or 0.0.0.0/0 for anywhere).发现解决方案是确保我的安全组包含 MySQL 端口 3306 的入站规则以包含我的 IP 地址(或任何地方的 0.0.0.0/0)。 Immediately could connect remotely as soon as I added this rule.添加此规则后,立即可以远程连接。

MySQL ODBC 3.51 Driver is that special characters in the password aren't handled. MySQL ODBC 3.51 Driver 是不处理密码中的特殊字符。

"Warning – You might have a serious headache with MySQL ODBC 3.51 if the password in your GRANT command contains special characters, such as ! @ # $ % ^ ?. MySQL ODBC 3.51 ODBC Driver does not support these special characters in the password box. The only error message you would receive is “Access denied” (using password: YES)" - from http://www.plaintutorials.com/install-and-create-mysql-odbc-connector-on-windows-7/ “警告——如果您的 GRANT 命令中的密码包含特殊字符,例如 !@# $ % ^ ?,您可能会对 MySQL ODBC 3.51 感到头疼。MySQL ODBC 3.51 ODBC 驱动程序不支持密码框中的这些特殊字符。您将收到的唯一错误消息是“访问被拒绝”(使用密码:是)“-来自http://www.plaintutorials.com/install-and-create-mysql-odbc-connector-on-windows-7/

The user/host combination may have been created without password.用户/主机组合可能是在没有密码的情况下创建的。

I was assuming that when adding a new host for an existing user (using a GUI app), the existing password would also be used for the new user/host combination.我假设在为现有用户(使用 GUI 应用程序)添加新主机时,现有密码也将用于新用户/主机组合。

I could log in with我可以登录

mysql -u username -p PASSWORD

locally, but not from IPADDRESS with本地,但不是来自 IPADDRESS

mysql -u --host=HOST -p PASSWORD

(I could actually log in from IPADDRESS without using a password) (我实际上可以不使用密码从 IPADDRESS 登录)

mysql -u --host=HOST

Setting the password allowed access:设置密码允许访问:

set password for '<USER>'@'<IPADDRESS>' = '<PASSWORD>';

mysql 配置文件的新位置是

/etc/mysql/mysql.conf.d/mysqld.cnf

My case is absolutely simple.我的情况非常简单。

You may have this problem in case if you type in WRONG password.如果您输入了错误的密码,您可能会遇到此问题。 No create user is needed (user already existed), no other permissions.不需要创建用户(用户已经存在),没有其他权限。 Basically make sure that the password is correct.基本上确保密码正确。 So make double-sure the password is correct因此,请确保密码正确

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL 错误 1045 (28000):用户“root”@“localhost”的访问被拒绝 - MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' Mac mysql错误1045(28000):用户&#39;root&#39;@&#39;localhost&#39;的访问被拒绝 - Mac mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' MYSQL错误:1045(28000):用户&#39;root&#39;@&#39;localhost&#39;拒绝访问 - MYSQL error: 1045 (28000): Access denied for user 'root'@'localhost' 错误1045(28000):用户&#39;root&#39;@&#39;%&#39;的访问被拒绝 - ERROR 1045 (28000): Access denied for user 'root'@'%' 错误1045(28000):访问被拒绝 - ERROR 1045 (28000): Access denied PDO 连接到外部 MySQL 数据库(来自 AWS)-“SQLSTATE[28000] [1045] 用户拒绝访问” - PDO connection to an external MySQL database (from AWS) - “SQLSTATE[28000] [1045] Access denied for user” MYSQL - LOAD DATA INFILE 给出 ERROR 1045 (28000): Access denied for user '<user> '@'<host> '(使用密码:是)</host></user> - MYSQL - LOAD DATA INFILE gives ERROR 1045 (28000): Access denied for user '<user>'@'<host>' (using password: YES) ERROR 1045 (28000): Access denied for user 'user'@'%' (使用密码: YES) - ERROR 1045 (28000): Access denied for user 'user'@'%' (using password: YES) 错误1045(28000):用户&#39;user&#39;@&#39;localhost&#39;的访问被拒绝 - ERROR 1045 (28000): Access denied for user 'user'@'localhost' MYSQL - 拒绝具有特定权限的新用户访问 - MYSQL 错误 1045(28000) - MYSQL - access denied to new user with specific permissions - MYSQL error 1045(28000)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM