Jump to content

[Solved] How to solve mysqli_connect(): (HY000/1045): Access denied for user error?


Hazak

Recommended Posts

I'm testing a remote connection to my Mysql DB and table.

 

I followed the basic procedure:

 

1 - I created DB ("employee101") by Mysql wizard.

2 - I created employee_data table by Myphpdamin.

3 - I created two DB users ("hazak" (cpanel user) and "remcon".

4 - I set users access and rights to "employee101" DB.

 

5 - I built two PHP scripts to remotely access Db and table, and put them in "hazak" public_html directory, as follows:

 

1 - conn.php (connection):

<?php
$db_name = "hazak_employee101";
$mysql_username = "hazak";
//$mysql_username = "remcon";
//$mysql_password = "&cx=Q******";
$mysql_password = "al********";
$server_name = "localhost:3306";
$conn = mysqli_connect($server_name, $mysql_username, $mysql_password, $db_name);
if($conn){
echo "connection success";
}
else{
echo "connection not success";
}
?>

 

2 - login.php (login):

 <?php

require "conn.php";
$user_name = $_POST["user_name"];
$user_pass = $_POST["password"];
$mysql_qry = "select * from employee_data where username like '$user_name' and password like '$user_pass';";
$result = mysqli_query($conn, $mysql_qry);
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_assoc($result);
$name = $row["name"]; 
echo "login success - user ".$name;
}
else{
echo "login not success";
}
mysqli_close($conn)
?>

 

6 - Remotely run the script. First using "hazak" user set in conn.php and second, using "remcon" user in the same script.

I got the same error message (bellow) and when I created an email acoount to "hazak" (cpanel) user the message gone away and I could remotely connect to DB and access "employee_data" table.  but the same didn't happened to the "remcon" user.

 

Since I could't find reference to this error on heliohost.org  Mysql pages I´m not sure about what is the error cause.

 

Can anybody tell the possible cause/solution for this error and help me?

 

Error message:

 

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'remcon'@'localhost' (using password: YES) in /home/hazak/public_html/remcon/conn.php on line 8

 

Link to comment
Share on other sites

Maybe the database you are trying to access it has been created by another user/with a different password or you don't have permission to access the database. Check the details in cPanel > MySQL Databases.

Link to comment
Share on other sites

Do you get any of the message as defined here:

if($conn){

echo "connection success";

}

else{

echo "connection not success";

}

If yes, then modify it to:

if($conn){

echo "connection success";

}

else{

echo "connection not success: ".mysqli_error($conn);

}

 

and see what mysql says.
  • Like 1
Link to comment
Share on other sites

@Sagnik: The access denied error he's getting will always make $conn false.

 

I would try changing the password on the mysql user next.

 

Also, this line would never be valid:

//$mysql_username = "remcon";

Except for the cPanel default mysql user (the one that's the same as your cpanel username), all MySQL users will be prefixed with cpanelusername_, so it should be It should be hazak_remcon, assuming hazak is your cPanel username.

Link to comment
Share on other sites

sagnik:

 

I did conn.php modification as you recommended.

Basically I got the same result and no new clue was showed, as follows:

 

 

( ! ) Warning: mysqli_connect(): (HY000/1045): Access denied for user 'remcon'@'179.157.27.166' (using password: YES) in C:\wamp64\www\conn_remx1.php on line 6 Call Stack # Time Memory Function Location 1 0.0007 235624 {main}( ) ...\conn_remx1.php:0 2 0.0007 236424 mysqli_connect ( ) ...\conn_remx1.php:6

 

( ! ) Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\wamp64\www\conn_remx1.php on line 11 Call Stack # Time Memory Function Location 1 0.0007 235624 {main}( ) ...\conn_remx1.php:0 2 5.3416 237160 mysqli_error ( ) ...\conn_remx1.php:11

connection not success: 

Link to comment
Share on other sites

That's running on your local computer on WAMP...the file needs to actually be on our server to work with the settings you listed.

 

If you want to run the scripts from a server that's not ours, you need to enable remote mysql in cPanel (add the remote server's IP, or % to allow any), then use johnny.heliohost.org instead of localhost for the hostname.

Link to comment
Share on other sites

The Root Admin recommendation works remotely from my Wampserver php script. (user name prefix)

Now I´m going to test running directly on my heliohost.org www directory.

I hope there will be no problem.

Thanks mates.

Link to comment
Share on other sites

Root Admin:

When I run the new conn.php script (changing user name to "hazak_remcon") in my www heliohost.org directory (using localhost as host), I got the same success result.

Thanks for support.

Edited by Hazak
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...