This is really strange, for my user root I've set the password to:
roboasd231
I can access the MySQL server from Sequel Pro just fine, however when i try to login from PHP using the exact same details i get this error:
Access denied for user 'root'#'localhost' (using password: YES)
Any ideas how to resolve this?
This is my php code:
$con = mysql_connect("localhost","root","roboasd231");
if (!$con)
{
die('Cant connect: ' . mysql_error());
}
Screen of my users table in mysql db
You mosto likely need to enable root access from a remote workstation ...
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'roboasd231';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY 'roboasd231';
FLUSH PRIVILEGES;
If the problem is connecting from localhost is because '%' doesn't include localhost access, try to use the net interface IP, for example (192.168.1.1 or whatever else you have).
Otherwise you can add the granting even to localhost, as showed above in the code section of this answer.
Related
I can access my database with
mysql -u root -p
and then by entering my password.
But when I try to login through a php script
$link = mysqli_connect('localhost', 'root', 'mypassword');
I get the following error
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in /Library/WebServer/Documents/connect/index.php on line 6
When I run
SELECT USER(),CURRENT_USER();
in MySQL, I get the following (reformatted)
root#localhost | root#localhost
So I know the three parameters in my login function are correct, but I am not able to sign in.
I would appreciate any help.
Edit: Here are the grants
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD '*0503AA35367B049092549C66DFE0D6C3AA3C4970' WITH GRANT OPTION || GRANT PROXY ON ''#'' TO 'root'#'localhost' WITH GRANT OPTION
EDIT: just to be explicit, what solved my problem was using 127.0.0.1 instead of localhost.
This error is usually because of an incorrect username password combination.
User root normally has no password unless you've added one. Try going into PHPMYADMIN or other config files and dig up the password for root.
Another issuer is, you could try connecting to a specific database (the fourth parameter of mysqli_connect and do a SHOW GRANTS on user root) to ensure you have the privileges. root may not have the necessary grants, and I think that is what could be happening.
https://dev.mysql.com/doc/refman/5.0/en/show-grants.html
Edit: Answer in the comments, changed localhost to 127.0.0.1, likly some configuration stuff in the server hosting environment
I have setup a MySQL database and I am trying to connect to it from another website.
I get this error when I try to connect to it:
Connection failed: Access denied for user 'myUsername'#'localhost' (using password: YES)
It works fine when I do it in the same website where the database is hosted.
I tried this SQL query:
GRANT SELECT, DELETE, UPDATE ON database.myDatabaseName TO 'myUsername'#'localhost' IDENTIFIED BY 'myPassword';
But I got this error:
#1142 - SELECT,UPDATE,DE command denied to user 'Steve'#'localhost' for table 'myDatabaseName'
I went to the MySQL management in the built-in control panel where I modified permissions of Steve and added the Grant permission, however I still get the same #1142 error.
How can I fix this?
Thanks in advance.
Access denied for user 'myUsername'#'localhost' (using password: YES)
That's where the error is. It says you are attempting to connect to localhost with the username myUsername and a supplied password. However, usually on localhost, especially on windows systems, the user is Root and the password is not set, just an empty string. Check your username on your localhost and your password.
I've Installed mysql, php, apache using a wamp configuration
Where to access localhost is would be http://localhost:81
the PHP script I'm using is
if(mysql_connect('localhost', 'root', 'exobytes15')) {
mysql_select_db('testDB');
}
else {
echo 'Could not Connect to the database';
}
But this gives me the error
1045: Access denied for user 'root'#'localhost' (using password: YES)
What should I do to fix this problem?
Either you didn't grant root#localhost the necessary rights to access the database or you're providing the wrong password.
Note : granting access to root#`%` does NOT grant access to root#localhost...
Make sure you have that your database is running, and that the user has access to it.
You can use either use the plain old mysql commandline client for this or phpmyadmin if your wamp stack has that installed.
You're connecting with the wrong password: Reset the password
or more likely: you don't have privileges to connect from localhost.
Run the command:
GRANT ALL PRIVILEGES ON *.* TO 'root'#localhost WITH GRANT OPTION;
Test to see if you can connect.
Never do: GRANT ALL PRIVILEGES ON *.* TO 'root'#% WITH GRANT OPTION;
Because that will put your database server at risk from remote login attempts.
Maybe u are running mysql on a port other than the default port.
If it is the case use this:
mysql_connect('localhost:PORT', 'root', 'exobytes15')
I have created a database by name 'somedatabase' in mysql
CREATE DATABASE somedatabase;
GRANT ALL ON somedatabase.* TO 'someuser'#'localhost' IDENTIFIED BY 'somepassword';
but when i try to access this database using php application i get the following error
"mysql_connect() [function.mysql-connect]: Access
denied for user 'someuser'#'localhost' (using password: YES)"
The Mysql query browser does allow me to login to this database using username : someuser and password : somepassword. Then why is that i am not able to connect to database through application.
php code :
$db_url = 'mysql://someuser:*somepassword*#localhost/somedatabase';
Do not use singlequote (') around someuser when using GRANT.
GRANT ALL ON somedatabase.* TO someuser#'localhost' IDENTIFIED BY 'somepassword';
I am also assuming that you're running Apache/PHP on the same box as MySQL.
I had same problem. the solution of my problem by was setting the host , for some reason php was not connecting for user at any host (%)
Try this:
GRANT ALL PRIVILEGES ON somedatabase.* TO 'someuser'#'%' IDENTIFIED BY 'somepassword';
http://dev.mysql.com/doc/refman/4.1/en/adding-users.html
I have set up an Apache server on mandriva linux 2010.1. But the problem is whenever I'm trying to connect with the database, it's giving me the following error:
Error:Database error: SQLSTATE[28000]
[1045] Access denied for user
'root'#'myhostname' (using password:
YES)
Normally for a web application, you shouldn't connect to the database as root. However you tagged your post as [phpmyadmin] so I assume your issue is with, well, phpMyAdmin, in which case you might be connecting as root.
If this is the case, I see that you mentioned myhostname in your error message. Have you tried connecting to localhost instead? Sometimes the MySQL root user cannot connect from remote hosts.
you need to set some configuration variables for phpmyadmin to work:
http://www.phpmyadmin.net/documentation/Documentation.html#config
GRANT ALL PRIVILEGES ON *.* TO monty#localhost
IDENTIFIED BY 'indian' WITH GRANT OPTION;
Replace your username and password and execute it in your phpmyadmin by selecting your database.
Take a look at "5.4.7. Causes of Access-Denied Errors" in the MySQL online documentation and Using authentication modes" in the PHPMyAdmin documentation.