【问题标题】:Webserver and MySQL server on same machine "Error :(28000/1045) Access denied for user "同一台机器上的 Web 服务器和 MySQL 服务器“错误:(28000/1045) 用户访问被拒绝”
【发布时间】:2015-12-13 09:51:49
【问题描述】:

先说一些细节:: 在 Ubuntu 14.10 LTS 上运行 MySQL 5.6,Apache 作为网络服务器。 服务器位于路由器后面,因此端口 80 和 3306 被转发并且正常。 网络服务器运行良好。

MySQL 用户列表:

mysql> select user, host from mysql.user;
+------------------+-------------------+
| user             | host              |
+------------------+-------------------+
| userA            | %                 |
| root             | 127.0.0.1         |
| debian-sys-maint | localhost         |
| phpmyadmin       | localhost         |
| root             | localhost         |
| userA            | localhost         |
| root             | elite81           |
+------------------+-------------------+

my.cnf 文件

`[客户端]

port        = 3306
socket      = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 0.0.0.0

`

问题:: 只有“root”可以访问 MySQL 数据库。我想使用“userA”进行访问,但出现以下错误代码:

A) 当php代码中的host值为:服务器的外部IP地址时

Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'userA'@'router.asus.com' (using password: YES)

B) 当主机值为:127.0.0.1

Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'userA'@'localhost' (using password: YES)

尝试纠正此问题失败:

哈希绑定地址 / 将绑定地址更改为 192.168.1.87(本地 IP 地址)/ 将绑定地址更改为外部 IP 地址 /

还尝试在网络内连接 - 不起作用/

也完成了 FLUSH PRIVILEGES;在 MySQL 中。

在网上浏览了几篇相关的帖子,但没有解决! :-( 需要帮助。

另外,我有一个问题。 当网络服务器与 MySQL 服务器在同一台机器上运行时,php 连接文件中的主机应该是什么?

【问题讨论】:

  • 附加信息:我可以在机器上连接为mysql -u userA -p -hlocalhost,但不能连接为mysql -u userA -p -h11.11.11.11
  • 删除userA@% 进行检查:没有用

标签: php mysql apache


【解决方案1】:

已解决:

  1. 在 MySQL 中创建一个新用户(对所有数据库具有授予权限和完全权限)从任何主机访问;然后FLUSH PRIVILEGES;

  2. 在php连接中,host作为服务器的外部ip地址。

  3. 在my.cnf文件中,绑定地址:0.0.0.0
  4. 然后连接成功。

  5. 降低了新帐户的权限。 (没有管理权限,没有维护权限,只能使用一个数据库。)

  6. 完成。

【讨论】:

    猜你喜欢
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    • 2015-01-27
    • 2017-08-23
    • 1970-01-01
    • 2021-04-25
    相关资源
    最近更新 更多