简体   繁体   中英

Access denied for user 'www-data'@'localhost'

I am getting this errors when I run my code. How can I change the user www-data to root ?

//Errors recorded in Terminal

[Tue Mar 03 10:33:01.023877 2015] [:error] [pid 3161] [client 127.0.0.1:37725] PHP Warning:  mysql_query(): Access denied for user 'www-data'@'localhost' (using password: NO) in /var/www/html/wow/register.php on line 23, referer: http://localhost/wow/register.php

[Tue Mar 03 10:33:01.023957 2015] [:error] [pid 3161] [client 127.0.0.1:37725] PHP Warning:  mysql_query(): A link to the server could not be established in /var/www/html/wow/register.php on line 23, referer: http://localhost/wow/register.php


// Codes inside register.php
<?php
require('config.php');

if(isset($_POST['submit'])){

    //Perform the verification of the nation
      $email = $_POST['email'];
      $confirmEmail = $_POST['confirmEmail'];
      $pass = $_POST['pass'];
      $confirmPass = $_POST['confirmPass'];

        if($email == $confirmEmail){
            if($pass == $confirmPass){
                //All good, Carry on.
                  $firstName = mysql_escape_string($_POST['firstName']);
                  $lastName = mysql_escape_string($_POST['lastName']);
                  $userName = mysql_escape_string($_POST['userName']);
                  $email = mysql_escape_string('email');
                  $confirmEmail = mysql_escape_string('confirmEmail');
                  $pass = mysql_escape_string('pass');
                  $confirmPass = mysql_escape_string('confirmPass');

        mysql_query("INSERT INTO `users` (`id`, `firstName`, `lastName`, `userName`, `email`, `pass`) VALUES (NULL, '$firstName', '$lastName', '$userName', '$email', '$pass')") or die("Can't Connect!");


            } else{
                echo "Sorry, your passwords do not match. <br />";
            }

        } else {
            echo "Sorry, your email's do not match. <br />";
        }
} else{

    $form = <<<EOT
        <form action="register.php" method="POST">
            First Name: <input type="text" name="firstName"/><br />
            Last Name: <input type="text" name="lastName"/><br />
            Username: <input type="text" name="userName"/><br />
            Email: <input type="text" name="email"/><br />
            Confirm Email: <input type="text" name="confirmEmail"/><br />
            Password: <input type="password" name="pass"/><br />
            Confirm Password: <input type="password" name="confirmPass"/><br />

            <input type="submit" value="Register" name="submit"/>
        </form>
EOT;

}

echo $form;

?>

The first error is when you trying to connect to the Database.

On config.php you might see something like www-data as your database user, change it to the right username and password.

Also you can search the word www-data in your project.

You got the second error because the first error. Since your connection failed your link is null

Your MySQL username or password is incorrect (it is currently blank) or the user www-data is not allowed to connect on the domain localhost.

You need to create a user in MySQL and assign access and privileges to that database or if already done, check that you put the correct details.

Also, mysql_connect and 'mysql' functions are depreciated now. Upgrade to mysqli.

Some references you can use to get started.

https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial

https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

http://codular.com/php-mysqli

where is the db? are you using godaddy hosting? it seems there are multiple websites affected with this error from yesterday Mar 3rd around 16:10 UTC. (your time matches with this incident) if you are sure the username, p/w or privilege of the user id was not changed, check with the db admin to do some restoration of the id. (PS: my points do not allow comment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM