Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

access denied

Posted on 2013-06-12
22
Medium Priority
?
384 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
ID: 39240901
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 7

Expert Comment

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

Expert Comment

by:Ray Paseur
ID: 39240943
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:jagguy
ID: 39241154
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 7

Expert Comment

by:Robert Saylor
ID: 39241163
Are you using a control panel?
0
 
LVL 15

Expert Comment

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

Author Comment

by:jagguy
ID: 39241233
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
ID: 39241329
Why not use root user to complete your needs it's just your localhost.
0
 

Author Comment

by:jagguy
ID: 39241344
ok but why doesnt the user name work?
0
 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39241369
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
ID: 39241709
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
 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39241722
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
ID: 39243067
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
ID: 39243399
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
ID: 39246376
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 7

Expert Comment

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

Author Comment

by:jagguy
ID: 39270145
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
ID: 39270150
Can you access database using root user with no password try it?
0
 

Author Comment

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

Expert Comment

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

Author Comment

by:jagguy
ID: 39276536
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 2000 total points
ID: 39276747
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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

916 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