Solved

access denied

Posted on 2013-06-12
22
361 Views
Last Modified: 2013-06-30
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
0
Comment
Question by:jagguy
  • 8
  • 6
  • 5
  • +2
22 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
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
 
LVL 6

Expert Comment

by:Robert Saylor
Comment Utility
Are you sure it's "localhost" ? This is common to use but some control panels does not use localhost.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
 

Author Comment

by:jagguy
Comment Utility
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
 
LVL 6

Expert Comment

by:Robert Saylor
Comment Utility
Are you using a control panel?
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
Add a new user with all privilege and change username and password there may be problem in previous user.
0
 

Author Comment

by:jagguy
Comment Utility
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
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
Why not use root user to complete your needs it's just your localhost.
0
 

Author Comment

by:jagguy
Comment Utility
ok but why doesnt the user name work?
0
 
LVL 6

Expert Comment

by:Robert Saylor
Comment Utility
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
 
LVL 23

Expert Comment

by:nemws1
Comment Utility
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 6

Expert Comment

by:Robert Saylor
Comment Utility
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
 

Author Comment

by:jagguy
Comment Utility
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
 
LVL 23

Expert Comment

by:nemws1
Comment Utility
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
 

Author Comment

by:jagguy
Comment Utility
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
 
LVL 6

Expert Comment

by:Robert Saylor
Comment Utility
Take a screen shot as root in phony admin with the database expanded on the left menu.
0
 

Author Comment

by:jagguy
Comment Utility
here are some screen shots to prove I have a user and password set but it doesnt work
mysql-ss.docx
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
Can you access database using root user with no password try it?
0
 

Author Comment

by:jagguy
Comment Utility
yes i can use root/ no password so what is the problem with a password?
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
No the root user is working and in your localhost or testing server you can use it no problem.
0
 

Author Comment

by:jagguy
Comment Utility
yes, but this question is going on too long.
if you don't know then I will end the question.
0
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 500 total points
Comment Utility
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now