Solved

access denied

Posted on 2013-06-12
22
372 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 109

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
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.

860 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