access denied

I create a db in mysql and a user jagguy. I gave user jagguy all privileges

I want to connect to the db  and display values from the table.
I cant connect to it without an error

<?php


$link = mysql_connect('localhost', 'jagguy', 'password');


?>
Warning: mysql_connect(): Access denied for user 'jagguy'@'localhost' (using password: YES) in E:\AA-website design\test11.php on line 4
jagguyAsked:
Who is Participating?
 
Jagadishwor DulalConnect With a Mentor Braces MediaCommented:
You have phpmyadmin and you are testing on the localhost that's why use root user without password for testing purpose you don't need another user for localhost. In your hosting you will be able to create user for site and can manage password and required options in cpanel. Again you can remove unnecessary users from your phpmyadmin and create again with password and previllage, I hope it will work.
0
 
Jagadishwor DulalBraces MediaCommented:
It means set all privilege again to jagguy and try again write die condition also like:
$link=mysql_connect("localhost", "jagguy", "password") or die(mysql_error());

Open in new window


That will display error also
0
 
Robert SaylorSenior DeveloperCommented:
Are you sure it's "localhost" ? This is common to use but some control panels does not use localhost.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Ray PaseurCommented:
Try it this way.  Put your actual credentials in line 8-11.

<?php // RAY_mysqli_example.php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);
echo '<pre>';


// DATABASE CONNECTION AND SELECTION VARIABLES - GET THESE FROM YOUR HOSTING COMPANY
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";
$db_user = "??";
$db_word = "??";

// OPEN A CONNECTION TO THE DATA BASE SERVER AND SELECT THE DB
$mysqli = new mysqli($db_host, $db_user, $db_word, $db_name);

// DID THE CONNECT/SELECT WORK OR FAIL?
if ($mysqli->connect_errno)
{
    $err
    = "CONNECT FAIL: "
    . $mysqli->connect_errno
    . ' '
    . $mysqli->connect_error
    ;
    trigger_error($err);
}

// SHOW WHAT THE DB CONNECTION OBJECT LOOKS LIKE
var_dump($mysqli);

Open in new window

0
 
jagguyAuthor Commented:
The mysql db is on my PC 'local copy' and not on a remote server.

I tried the above and nothing works. It must be a user privilege but I cant see what to do.

Warning:  mysqli::mysqli(): (HY000/1045): Access denied for user 'jagguy'@'localhost' (using password: YES) in E:\AA-website design\test12.php on line 16

Notice:  CONNECT FAIL: 1045 Access denied for user 'jagguy'@'localhost' (using password: YES) in E:\AA-website design\test12.php on line 27

Warning:  var_dump(): Property access is not allowed yet in E:\AA-website design\test12.php on line 31



Warning:  var_dump(): Property access is not allowed yet in E:\AA-website design\test12.php on line 31



Warning:  var_dump(): Couldn't fetch mysqli in E:\AA-website design\test12.php on line 31
0
 
Robert SaylorSenior DeveloperCommented:
Are you using a control panel?
0
 
Jagadishwor DulalBraces MediaCommented:
Add a new user with all privilege and change username and password there may be problem in previous user.
0
 
jagguyAuthor Commented:
I am using my local phpAdmin not a control panel

I did another user for the Db and what is going on with this?
It works with user root and no password.


Warning:  mysqli::mysqli(): (HY000/1045): Access denied for user 'user1'@'localhost' (using password: YES) in E:\AA-website design\test12.php on line 16



Notice:  CONNECT FAIL: 1045 Access denied for user 'user1'@'localhost' (using password: YES) in E:\AA-website design\test12.php on line 27
0
 
Jagadishwor DulalBraces MediaCommented:
Why not use root user to complete your needs it's just your localhost.
0
 
jagguyAuthor Commented:
ok but why doesnt the user name work?
0
 
Robert SaylorSenior DeveloperCommented:
from mysql as root:

grant all on databasename.* TO username@'localhost' IDENTIFIED BY 'password';

change databasename to your database
change username to your username
change password to your password

Then try the connection again.
0
 
nemws1Database AdministratorCommented:
For giggles, try using '127.0.0.1' instead of 'localhost'.  Both should work just fine, but I would just want to rule that out as an issue.

Have you tried another MySQL client, like trying MySQLWorkbench and seeing if you can connect with that?
0
 
Robert SaylorSenior DeveloperCommented:
if he created the user but did not set permissions then he would have to execute the GRANT statement first. Even on 127.0.0.1 the same would have to be done.

Example:

grant all on databasename.* TO username@'127.0.0.1' IDENTIFIED BY 'password';
0
 
jagguyAuthor Commented:
My php has changed dir from the default so i wonder is this an issue for new users?
I also tried this and i checked all privelliges .

The Table       Privileges       Grant       Column-specific privileges       Action is none so is this an issue?


GRANT ALL PRIVILEGES ON `db\_jagguy` . * TO 'user1'@'localhost' WITH GRANT OPTION ;


Warning: mysql_connect(): Access denied for user 'user1'@'localhost' (using password: YES)
0
 
nemws1Database AdministratorCommented:
Does your database name actually have a slash in it?  That might be the issue.  Or are you trying to backslash the understore?  (Which 1) you don't need to do and 2) you wouldn't need to do in backtics anyways)
0
 
jagguyAuthor Commented:
no my db doesnt have a slash but it appears on the warning. I had an underscore but the other db didnt work without an underscore.

Sounds like a quirk in mysql?
0
 
Robert SaylorSenior DeveloperCommented:
Take a screen shot as root in phony admin with the database expanded on the left menu.
0
 
jagguyAuthor Commented:
here are some screen shots to prove I have a user and password set but it doesnt work
mysql-ss.docx
0
 
Jagadishwor DulalBraces MediaCommented:
Can you access database using root user with no password try it?
0
 
jagguyAuthor Commented:
yes i can use root/ no password so what is the problem with a password?
0
 
Jagadishwor DulalBraces MediaCommented:
No the root user is working and in your localhost or testing server you can use it no problem.
0
 
jagguyAuthor Commented:
yes, but this question is going on too long.
if you don't know then I will end the question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.