MySQL Forums
Forum List  »  Install & Repo

Error Connecting to DataBase!: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
Posted by: Amanda J
Date: October 06, 2017 02:51PM

I recently set up a local WAMP Server (my first ever so please mind the vertical learning curve)

Configuration
    Apache Version: 2.4.27
    PHP Version: 5.6.31
    Server Software: Apache/2.4.27 (Win64) PHP/5.6.31 - Port defined for Apache: 80
    MySQL Version: 5.7.19 - Port defined for MySQL: 3306
I installed using the default settings. Including no password on the root directory.

mysql> show grants for root@localhost;
mysql> SELECT User, Host, HEX(authentication_string) FROM mysql.user;
+---------------+-----------+------------------------------------------------------------------------------------+
| User          | Host      | HEX(authentication_string)                                                         |
+---------------+-----------+------------------------------------------------------------------------------------+
| root          | localhost |                                                                                    |
| mysql.session | localhost | 2A5448495349534E4F544156414C494450415353574F52445448415443414E42455553454448 |
| mysql.sys     | localhost | 2A5448495349534E4F544156414C494450415353574F52445448415443414E42455553454448|
+---------------+-----------+------------------------------------------------------------------------------------+
I imported an existing database from a public shared server into the db and moved the public_html files for the website into a sub-directory of the WAMP directory.

    c://WAMP64/www/possbil
    c://WAMP64/www/private
The website I've migrated across requires the user enter a password to access the url. The site itself also requires a user name and p/w.

I removed the URL p/w access by not migrating the .htaccess file across.
I then modified the website and database files to reflect the localhost settings.

db.inc.php

<?php
//echo "db.inc.ihp loading; ";
$user="root";
$database="possbil";
$password="NULL";
$server='localhost';
$mysqli = mysqli_connect($server, $user, NULL, $database);
if (!$mysqli) {
    die('Could not connect: ' . mysql_error());
}
try { $pdom = new PDO("mysql:host=$server;dbname=$database", $user, $password); }
catch (PDOException $e) { print "Error Connecting to DataBase!: " . $e->getMessage() . "<br>"; die(); }
//echo 'Connected successfully';
//mysql_select_db($database);
?>

mysql.php

<?php
$mysql = mysqli_connect('localhost', 'root', 'NULL');
/* Test the MySQL connection */
if (mysqli_connect_errno()) {
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}
/* Print the MySQL server version */
printf("MySQL server version: %s\n", mysqli_get_server_info($mysql));
/* Close the MySQL connection */
mysqli_close($mysql);
?>
c://WAMP64/www/possbil contains:
    index.php
    mysql.php
    html directory and files
c://WAMP64/www/private contains:
    access.inc.ph
    db.inc.php
I have 2 problems:

When I follow the "possbil" directory link from the WAMP (localhost) GUI instead of opening the website as expected I get an error:

"possbil’s server DNS address could not be found."
"ERR_NAME_NOT_RESOLVED"

Specifically defining the DNS server setting (Windows 10) doesn't fix this issue -
    Preferred DNS server : 8.8.8.8
    Alternate DNS server : 8.8.4.4
If I manually enter the url "locahost/possbil/" in the browser. I get the error:

"Error Connecting to DataBase!: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)"

From the documentation this seems to imply that I'm somehow passing in a password for the user "root". And because there is no password set it is bouncing?

Assuming my thinking is even on the right page here, I'm a bit stumped where the password is coming from?

I know there is no password for the root user set, and from what I can grasp of php so far using "NULL"in the db.inc.php file should not be getting read as as a script?

I will be the only one using the local version so prefer not to have a password set.

Anyhow welcome any guidance on where to look next.

thanks

Options: ReplyQuote


Subject
Written By
Posted
Error Connecting to DataBase!: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
October 06, 2017 02:51PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.