用户“SYSTEM”@“localhost”访问被拒绝(PHP 5.2.17 + mySQL 5.5.8 + Windows 7)
我想在 PHP 5.2 环境中测试为 PHP 5.3.5 编写的脚本(作为 Apache 模块安装)。
我安装了 Apache 2.0.64 和 PHP 5.2.17 的全新副本,并完全按照我之前配置 PHP 5.3 的方式进行配置。除了我确实将 libmysql.dll
复制到 Apache bin 目录中(PHP 5.3 不再有此文件)。
两台服务器都是手动配置的(不是 XAMPP 版本或其他版本)并访问相同的本地安装的 mySQL Server 5.5.8。两台服务器都在系统帐户下作为 Windows Server 运行。
PHP 5.3 工作完美,PHP 5.2 返回错误:
Warning: mysql_connect() [function.mysql-connect]: Access denied
for user 'SYSTEM'@'localhost' (using password: NO) in C:\Tools\htdocs\myscript.php on line 33
我使用的 SQL 用户是在 PHP 代码中硬编码的,它不是 SYSTEM@localhost
。 SYSTEM 似乎是运行 Apache 的 Windows 帐户。 (如果我从管理员帐户启动 Apache,消息将更改为 Administrator@localhost
。)
默认用户(名称为“”)已在我的 SQL-Server 上删除。如果此空用户存在,则 PHP 5.2 会成功连接到数据库,但由于权限原因,数据库选择 (mysql_select_db
) 会失败。
I wanted to test a script written for PHP 5.3.5 (installed as Apache module) in PHP 5.2 environment.
I installed a fresh copy of Apache 2.0.64 and PHP 5.2.17 and configured it EXACTLY as I had configured PHP 5.3 before. Except I did copy libmysql.dll
into Apache bin directory (PHP 5.3 doesn't have this file anymore).
Both servers are configured by hand (not a XAMPP versions or something) and access the same locally installed mySQL Server 5.5.8. Both servers are running as Windows Server under the system account.
PHP 5.3 works perfectly, PHP 5.2 returns an error:
Warning: mysql_connect() [function.mysql-connect]: Access denied
for user 'SYSTEM'@'localhost' (using password: NO) in C:\Tools\htdocs\myscript.php on line 33
The SQL-user I am using is hardcoded in PHP code ant it is not SYSTEM@localhost
. SYSTEM seems to be a Windows account the Apache is running under. (If I start the Apache from the Administrator account, the message changes to Administrator@localhost
.)
The default user (with a name '') was deleted on my SQL-Server. If this empty-user exists, the PHP 5.2 connects to the database successfully, but fails on the database selection (mysql_select_db
) because of permissions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
php.ini
中on中的sql.safe_mode
(不是PHP安全模式),则PHP始终使用脚本所有者进行连接连接到 SQL 服务器,而不是mysql_connect()
中指定的用户。我在配置过程中混淆了
safe_mode
和sql.safe_mode
属性,花了我 6 个小时!答案在这里找到: http://www.php.net/manual /de/ref.mysql.php#72632
If the
sql.safe_mode
(NOT the PHP safe mode) in on in thephp.ini
, PHP is always using the script owner to connect to the SQL server and not the user specified inmysql_connect()
.I mixed up the property
safe_mode
andsql.safe_mode
during the configuration and it cost me 6 hours!The answer was found here: http://www.php.net/manual/de/ref.mysql.php#72632
问题是您没有为
mysql_connect
指定正确的用户名和密码。不要将它们留空(并让 PHP 使用默认用户),而是使用 GRANT(或 phpMyAdmin 或任何其他管理客户端)指定添加到 MySQL 的实际用户名和密码。允许无密码身份验证是一个巨大的禁忌。允许管理员在没有密码的情况下访问简直是太可怕了。相反,请为所有程序创建有限的用户帐户。仅在绝对必要时才使用特权帐户...
The problem is that you're not specifying the proper username and password for
mysql_connect
. Instead of leaving them blank (and letting PHP use the default user), specify an actual username and password that was added to MySQL usingGRANT
(or phpMyAdmin, or any other admin client).Allowing password-less authentication is a huge no-no. Allowing administrator access without a password is just plain horrific. Instead, create limited user accounts for all of your programs. Only use privileged accounts when absolutely necessary...