简体   繁体   English

错误:用户'www-data'@'localhost'拒绝访问

[英]Error: Access denied for user 'www-data'@'localhost'

I'm running a mysql database (managed through phpmyadmin) on a lubuntu virtual machine, which itself is on a mac 10.6. 我在lubuntu虚拟机上运行一个mysql数据库(通过phpmyadmin管理),该虚拟机本身在mac 10.6上。 Everything was working smoothly until earlier, (and I didn't touch any part of the login code!) when I got the following error on my pages: 当我在我的网页上收到以下错误时,一切都工作顺利,直到更早,(我没有触及登录代码的任何部分!)

Erreur : SQLSTATE[28000] [1045] Access denied for user 'www-data'@'localhost' (using password: NO) Erreur:SQLSTATE [28000] [1045]访问被拒绝用户'www-data'@'localhost'(使用密码:NO)

I don't understand where this error is coming from as I don't have a user called www-data on phpmyadmin and my files are supposed to be using the root account on the database: 我不明白这个错误来自哪里,因为我没有在phpmyadmin上有一个名为www-data的用户,我的文件应该使用数据库上的root帐户:

$dbname = 'name';
$dbuser = 'root';
$dbpass = '*****';
$dbhost = 'localhost';
try{
    $linkpdo = new PDO('mysql:host='.$dbhost.';'.$dbname.', '.$dbuser.' , '.$dbpass);
    $linkpdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exception $e) {
    die('Erreur : '.$e->getMessage());
}

After some googling I saw that people modified their config.conf file, but I don't know how or why. 经过一些谷歌搜索,我看到人们修改了他们的config.conf文件,但我不知道如何或为什么。

Use a double quoted string and the correct parameters for the connect, its easier to build using a double quoted string and $variable expansion. 使用双引号字符串和连接的正确参数,使用双引号字符串和$variable扩展更容易构建。

    $linkpdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
    $linkpdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
<?php

$dsn = 'mysql:dbname=name;host=localhost';
$user = 'root';
$password = '*****';


try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
?>

Try this code. 试试这个代码。 Checkout this link for more details http://php.net/manual/en/pdo.connections.php 有关更多详细信息,请访问此链接http://php.net/manual/en/pdo.connections.php

The user and password are separate parameters, http://php.net/manual/en/pdo.connections.php . 用户和密码是单独的参数, http://php.net/manual/en/pdo.connections.php

So take out the concatanation here-> .', '.$dbuser.' , '.$dbpass 所以在这里取出连接 - > .', '.$dbuser.' , '.$dbpass .', '.$dbuser.' , '.$dbpass . .', '.$dbuser.' , '.$dbpass

Connection should be: 连接应该是:

$linkpdo = new PDO('mysql:host='.$dbhost.';dbname='. $dbname, $dbuser, $dbpass);    

尝试这个 :

 $linkpdo = new PDO('mysql:host='.$dbhost.';dbname='.$dbname , $dbuser, $dbpass);

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

相关问题 用户&#39;www-data&#39;@&#39;localhost&#39;的访问被拒绝 - Access denied for user 'www-data'@'localhost' 访问被拒绝用户&#39;www-data&#39;@&#39;localhost - 如何处理? - Access denied for user 'www-data'@'localhost - how to deal with that? WordPress-mysql_query():生产服务器上用户&#39;www-data&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:NO)错误 - Wordpress - mysql_query(): Access denied for user 'www-data'@'localhost' (using password: NO) error on production server PHP mysql_real_escape_string():用户&#39;www-data&#39;@&#39;localhost&#39;的访问被拒绝 - PHP mysql_real_escape_string(): Access denied for user 'www-data'@'localhost' 用户&#39;www-data @&#39;localhost的访问被拒绝 - Access denied for user 'www-data@'localhost 用户ubuntu拒绝权限,但.csv文件上的用户www-data拒绝该权限 - Permission denied with user ubuntu but not with user www-data on .csv file Www-data用户访问/ var / www /之外的文件/文件夹 - Www-data User to Access files/folder outside of /var/www/ 如何授予www-data用户访问python salt模块的权限? - how to grant www-data user access to python salt module? samba 文件夹上的 www-data 权限被拒绝 - Permission denied for www-data on samba folder 访问被拒绝www-data @ localhost - Access denied www-data@localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM