mysqli访问被拒绝(42000/1044)linux权限?

时间:2022-02-02 19:19:30

I get the php error

我得到了php错误

mysqli::mysqli(): (42000/1044): Access denied for user 'sec_user01'@'localhost' to database 'secure_login'

mysqli: mysqli():(42000/1044):用户“sec_user01”@“localhost”访问数据库“secure_login”被拒绝

I created the database with:

我用:

CREATE DATABASE `secure_login`;
I created the user with 
CREATE USER 'sec_user'@'localhost' IDENTIFIED BY '**********************';
GRANT SELECT, INSERT, UPDATE ON `secure_login`.* TO 'sec_user'@'localhost';

I connect to the db using

我连接到数据库。

 include_once 'web_psl-config.php';   // As functions.php is not included
    $mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);

the config file is included successfully. this worked up till a few hours ago. The only thing I can think of that changed is that in my php script I made some folders with 755 access. Is it possible that the permissions from the files from which this script is executed are causing this error ?

成功包含配置文件。这件事一直持续到几个小时以前。我能想到的唯一改变是在php脚本中我创建了一些具有755访问权限的文件夹。执行此脚本的文件的权限是否可能导致此错误?

I am really stumped.

我真的难住了。

edit: I tested this with an ADODB connection

编辑:我用ADODB连接进行了测试

require('../scripts/adodb5/adodb.inc.php');
$ADODB_CACHE_DIR = 'adodb5cache'; 

$Host = "localhost";
$Database = "secure_login";
$Databasetype ="mysql";

// lijst users en passwd
$DbAdminUser="sec_user01";
$DbAdminUserPassword="**************";

$debug = true; //debug on
//$debug = false; //debug off
//admin connection
$dbconn = ADONewConnection($Databasetype);
$dbconn->Connect($Host, $DbAdminUser, $DbAdminUserPassword, $Database);

$query="SELECT * FROM members;";
$ammount=$dbconn->GetAll($query);
print_r($ammount);

and this works. Is this some kind of bug in mysqli ? I really hope I don't have to rewrite to use ADODB.

这工作。这是mysqli中的一种病毒吗?我真的希望我不用重写来使用ADODB。

5 个解决方案

#1


2  

Try to login into phpmyadmin with those credentials. If unsuccessful then your credentials might not matching.

使用这些凭证尝试登录phpmyadmin。如果不成功,那么您的凭据可能不匹配。

#2


0  

The grant statement was wrongly formatted

grant语句格式错误

GRANT SELECT, INSERT, UPDATE ON `secure_login`.* TO 'sec_user'@'localhost'; is wrong
GRANT SELECT, INSERT, UPDATE ON secure_login.* TO 'sec_user'@'localhost'; works.

Why did it work the first time I have no idea.

我第一次不知道为什么会这样。

#3


0  

i have had this error a few times before, and to my understanding, which is limited on this error is that a many of things could be causing it, first and foremost try to reset your password, the way you do this is by going into a terminal and type.

我之前有过几次这样的错误,我的理解是,这个错误是有很多原因导致的,首先,也是最重要的是要重新设置你的密码,你要做的就是进入终端输入。

$ mysqladmin -u root -p'oldpassword' password newpass

$ mysqladmin -u root -p'oldpassword' password' password' password newpass

make notice to fill in your credentials where oldpassword, password, and newpass.

请注意填写您的凭证,其中包括旧密码、密码和newpass。

then try my php script i made, it will show you what fields you left blank and will use default parameters for them if they are still blank. the comments that pop up will also disappear within 10 seconds.

然后尝试我编写的php脚本,它将显示您留下的字段,如果它们仍然是空的,将为它们使用默认参数。弹出的评论也将在10秒内消失。

file 1

文件1

index.php

index . php

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><meta http-equiv="content-language" content="en-US" />
<title>MySQL Connection test</title>
<script type="text/javascript">
window.onload = function()
{
    timedHide(document.getElementById('messages'), 10);
}

function timedHide(element, seconds)
{
    if (element) {
        setTimeout(function() {
            element.style.display = 'none';
        }, seconds*1000);
    }
}
</script>
</head>
<body>
<span id="messages">

<?php include "constant.php"; ?>

</span>
</body>
</html>

file 2

文件2

constant.php

constant.php

<?php
$database_ip = ""; //database ip adress goes inside quotes
$database_port = ""; //database port goes inside quotes
$database_name = ""; //database name goes inside quotes

$database_admin_user = ""; //admin username goes inside quotes
$database_admin_pass = ""; //admin password goes inside quotes

//do not modify anything past this point unless you know php well.

$database_link = null;

$database_defaults = array("127.0.0.","3306","MySQL","root","");
$error_defaults = array("error_no_101" => "required field *IP is empty, using default parameters!",
                        "error_no_102" => "required field *PORT is empty, using default parameters!",
                        "error_no_103" => "required field *NAME is empty, using default parameters!",
                        "error_no_104" => "required field *USER is empty, using default parameters!",
                        "error_no_105" => "required field *PASS is empty, using default parameters!");

if(empty($database_ip)){
    $database_ip = $database_defaults[0];
    echo $error_defaults["error_no_101"] . "<br/>";
}

if(empty($database_port)){
    $database_port = $database_defaults[1];
    echo $error_defaults["error_no_102"] . "<br/>";
}

if(empty($database_name)){
    $database_name = $database_defaults[2];
    echo $error_defaults["error_no_103"] . "<br/>";
}

if(empty($database_admin_user)){
    $database_admin_user = $database_defaults[3];
    echo $error_defaults["error_no_104"] . "<br/>";
}

if(empty($database_admin_pass)){
    $database_admin_pass = $database_defaults[4];
    echo $error_defaults["error_no_105"] . "<br/>";
}

$database_link = mysqli_connect($database_ip, $database_admin_user, $database_admin_pass, $database_admin_pass);

if (!$database_link) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

echo 'Success... ' . mysqli_get_host_info($database_link) . "\n";

mysqli_close($database_link);

?>

i hoped this helped (=

我希望这对我有帮助

#4


0  

THis error disappear when you add some privileges except the insert select update in user privileges! So go add add all the privileges in cpanel with username and database name.

当您添加除了用户特权中的insert select update之外的一些特权时,这个错误就消失了!因此,添加cpanel中的所有权限,包括用户名和数据库名。

#5


0  

  1. Login to your cpanel (www.example.com/cpanel)
  2. 登录cpanel (www.example.com/cpanel)
  3. Go to MySQL add database wizard
  4. 转到MySQL添加数据库向导
  5. similar to "add database", "add_user" you will have a button to add user" to the "database".
  6. 类似于“添加数据库”、“add_user”,您将有一个向“数据库”添加用户的按钮。
  7. click on it,
  8. 点击它,
  9. added user should list under "priviledged user" for that "database".
  10. 添加的用户应该在“被特权用户”下列出该“数据库”。

#1


2  

Try to login into phpmyadmin with those credentials. If unsuccessful then your credentials might not matching.

使用这些凭证尝试登录phpmyadmin。如果不成功,那么您的凭据可能不匹配。

#2


0  

The grant statement was wrongly formatted

grant语句格式错误

GRANT SELECT, INSERT, UPDATE ON `secure_login`.* TO 'sec_user'@'localhost'; is wrong
GRANT SELECT, INSERT, UPDATE ON secure_login.* TO 'sec_user'@'localhost'; works.

Why did it work the first time I have no idea.

我第一次不知道为什么会这样。

#3


0  

i have had this error a few times before, and to my understanding, which is limited on this error is that a many of things could be causing it, first and foremost try to reset your password, the way you do this is by going into a terminal and type.

我之前有过几次这样的错误,我的理解是,这个错误是有很多原因导致的,首先,也是最重要的是要重新设置你的密码,你要做的就是进入终端输入。

$ mysqladmin -u root -p'oldpassword' password newpass

$ mysqladmin -u root -p'oldpassword' password' password' password newpass

make notice to fill in your credentials where oldpassword, password, and newpass.

请注意填写您的凭证,其中包括旧密码、密码和newpass。

then try my php script i made, it will show you what fields you left blank and will use default parameters for them if they are still blank. the comments that pop up will also disappear within 10 seconds.

然后尝试我编写的php脚本,它将显示您留下的字段,如果它们仍然是空的,将为它们使用默认参数。弹出的评论也将在10秒内消失。

file 1

文件1

index.php

index . php

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><meta http-equiv="content-language" content="en-US" />
<title>MySQL Connection test</title>
<script type="text/javascript">
window.onload = function()
{
    timedHide(document.getElementById('messages'), 10);
}

function timedHide(element, seconds)
{
    if (element) {
        setTimeout(function() {
            element.style.display = 'none';
        }, seconds*1000);
    }
}
</script>
</head>
<body>
<span id="messages">

<?php include "constant.php"; ?>

</span>
</body>
</html>

file 2

文件2

constant.php

constant.php

<?php
$database_ip = ""; //database ip adress goes inside quotes
$database_port = ""; //database port goes inside quotes
$database_name = ""; //database name goes inside quotes

$database_admin_user = ""; //admin username goes inside quotes
$database_admin_pass = ""; //admin password goes inside quotes

//do not modify anything past this point unless you know php well.

$database_link = null;

$database_defaults = array("127.0.0.","3306","MySQL","root","");
$error_defaults = array("error_no_101" => "required field *IP is empty, using default parameters!",
                        "error_no_102" => "required field *PORT is empty, using default parameters!",
                        "error_no_103" => "required field *NAME is empty, using default parameters!",
                        "error_no_104" => "required field *USER is empty, using default parameters!",
                        "error_no_105" => "required field *PASS is empty, using default parameters!");

if(empty($database_ip)){
    $database_ip = $database_defaults[0];
    echo $error_defaults["error_no_101"] . "<br/>";
}

if(empty($database_port)){
    $database_port = $database_defaults[1];
    echo $error_defaults["error_no_102"] . "<br/>";
}

if(empty($database_name)){
    $database_name = $database_defaults[2];
    echo $error_defaults["error_no_103"] . "<br/>";
}

if(empty($database_admin_user)){
    $database_admin_user = $database_defaults[3];
    echo $error_defaults["error_no_104"] . "<br/>";
}

if(empty($database_admin_pass)){
    $database_admin_pass = $database_defaults[4];
    echo $error_defaults["error_no_105"] . "<br/>";
}

$database_link = mysqli_connect($database_ip, $database_admin_user, $database_admin_pass, $database_admin_pass);

if (!$database_link) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

echo 'Success... ' . mysqli_get_host_info($database_link) . "\n";

mysqli_close($database_link);

?>

i hoped this helped (=

我希望这对我有帮助

#4


0  

THis error disappear when you add some privileges except the insert select update in user privileges! So go add add all the privileges in cpanel with username and database name.

当您添加除了用户特权中的insert select update之外的一些特权时,这个错误就消失了!因此,添加cpanel中的所有权限,包括用户名和数据库名。

#5


0  

  1. Login to your cpanel (www.example.com/cpanel)
  2. 登录cpanel (www.example.com/cpanel)
  3. Go to MySQL add database wizard
  4. 转到MySQL添加数据库向导
  5. similar to "add database", "add_user" you will have a button to add user" to the "database".
  6. 类似于“添加数据库”、“add_user”,您将有一个向“数据库”添加用户的按钮。
  7. click on it,
  8. 点击它,
  9. added user should list under "priviledged user" for that "database".
  10. 添加的用户应该在“被特权用户”下列出该“数据库”。