Access denied for user root#localhost on Ubuntu and OS X - mysql

I'm developing a web application and it is working just fine in Windows, but now I'm trying to run it in Ubuntu and in a Macbook and it's giving me a Access denied error.
The error doesn't allow me to retrieve information from the database, but let me enter the web application.
I can access to localhost/myApplication, but can't retrieve the database info.
The thing is that I can access the database if I change my code's hostname to 127.0.0.1, but I don't want to do that, I want to keep it as localhost.
I've tried everything I found around Internet, like:
I've changed my hosts file to listen to 127.0.0.1 localhost. I've granted all privileges to my user and flushed them. I've uninstalled and reinstalled Xampp and MySQL. I've changed my.cnf, php.ini, socket location and any other config files inside Xampp folder, but nothing worked.
The error it gives me and my code:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
My code:
$conn = new PDO("mysql:host=localhost;dbname=mydb", $db_user, $db_pass);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
I know that if I change localhost to 127.0.0.1 I can have access, but I want to keep it as localhost because I don't want to change all my other applications to listen to 127.0.0.1.

Related

mysqli::real_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: NO) error on Mac

This is the error message I got after I tried to make a password and username for localhost and root. Please help me. I am using Mac by the way.
MySQL said: Documentation
Cannot connect: invalid settings.
mysqli::real_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: NO)
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.
go to xampp\mysql\bin\my.ini and open it. change the port to 3307
and go to xampp\phpMyAdmin\config.inc.php and check the name of the host
$cfg['Servers'][$i]['host'] = 'localhost:3307';
Adding to soufiane's answer above, there is actually 2 more places where you have to make the same change:
xampp window: config > Service and Port Settings > mysql > Change port to 3307
add $cfg['Servers'][$i]['port'] = 3307; to phpMyAdmin\config.inc.php
For a complete start to finish solution, refer to this answer on Quora by Owais R. Mir: https://www.quora.com/How-do-I-change-the-port-of-a-MySQL-server-in-XAMPP/answer/Owais-R-Mir
PS:
I used this solution to run mysql from xampp on port 3307 because I had installed mysql separately before and it was using port 3306. When ports are reset for xampp mysql you avoid issues with initializing and signing in to your local database via phpmyadmin.

Unable to connect to MySQL server from VPS but able to from desktop

I'm connecting to my MySQL server that is hosted remotely using the MySQL-connector package in python. I created a user for my home computer with my home IP address which works just fine and can connect without any issues whatsoever.
But whenever I've tried to either:
a). Create a new user, grant privileges and connect from a secondary VPS
or
b). Create a new user that is on the MySQL server VPS (localhost), granted privileges and then tried to connect to the MySQL server
I've time over time encountered this error:
1045 (28000): Access denied for user 'username'#'localhost' (using password: YES)
(when I tried option a the IP would be my VPS's IP).
I really have no clue how I would go about fixing this. My bind-address is set to 0.0.0.0 and my firewall is inactive/open to everyone on port 3306.
If any of you got any suggestions on how I can fix this please let me know

Unable to connect to mysql remotely

I have a mysql database running on a VPS. I can ssh into the host and connect to mysql with no problems. I cannot connect to mysql remotely from my desktop. I have performed the following:
opened port 3306 on the firewall
added my local IP to the remote IPs accepted by mysql. This was done via CPanel
executed
GRANT ALL ON dbname.* TO username#'x.x.x.x' IDENTIFIED BY 'PASSWORD'
to tell mysql to let me connect from the specified address.
I execute the following from the command line on my desktop:
mysql -h x.x.x.x -u username -p
I get a password prompt which indicates I am past the firewall and mysql is responding. When I supply the password, it denies access:
ERROR 1045 (28000): Access denied for user 'username'#'x.x.x.x' (using password: YES)
Have I missed something?
The answer was given in the comments, so I will repeat it here to properly close the thread. alvits suspected that the remote user had not been created. It had been created but his comment prompted me to clean up the user table.
I deleted all remote users including loads that had been created by CPanel or migrated from another host. I then started from scratch doing create user and grant all and it works now.
Thanks!

Mysql - 1045 - Access denied for user 'user'#'localhost' (using Password: Yes)

I have installed MYSQL 5.6 stand-alone on a local windows server. Recently, I changed the local IP of my server and reconfigured it in my network, but now I am not able to access my databases. It is giving me this error:
1045 - Access denied for user 'user'#'localhost' (using Password: Yes)
The above error is coming while using localhost as the server name. Also, I am able to connect to localhost through root username, but it is not showing me the original DB's which I had before.
Also before the server IP change I was able to access the MySQL server through the old IP of the server. like host name: xx:xx:xx:xx , user: user, pass: pass .... But it is also giving me an error:
2003 - cannot connect to my sql server on 'xx:xx:xx:xx' (10038)
I have tried the solution define on following link and run following query:
https://dev.mysql.com/doc/mysql-windows-excerpt/5.6/en/resetting-permissions-windows.html
SET PASSWORD FOR 'root'#'%' = PASSWORD('test');
and this is starting giving error of access denied for the root username and password 'test'
Can any body help me to resolve this.
Connect to 127.0.0.1 as root.
Update IP address for mysql user row with old IP address.
use mysql;
update user set host='NEWIP' where host='OLDIP' and user='root';
flush privileges;
Try again to connect.
If you don't have root access, reset permissions and try again.
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
This is a problem experienced by people who downloaded the recent version (i.e MySQL 5.7.10)
The problem is there is a temporary password for this version
after you typed in bin>mysql -u root -p ...
you have to type in the password which is different for every person who downloaded it. Go to your mysql directory in C (or wherever you extracted it to) , go to the file 'data'. There would be an ERR file with your computer's name on it.
Open that file using notepad
in the 6th line of commands, there would be a line as follows
[Note] A temporary password is generated for root#localhost: '(your password)'
copy that password and paste it in the command prompt ... From there on you can continue as shown in the video

Access denied to remote MySQL connection request

I have a mysql database (v5.5.41) setup on a remote server and an application connects to the DB from another server to run some queries. It's been working fine but recently my DB server got a new IP address. My application can't connect to the DB anymore, the connection times out.
The application is using the DNS name of the server, not a hard-coded IP, so there shouldn't be a problem. In any case, if I run this from the application server:
mysql -u app_user -h mydb.myhost.com -p
then I get
ERROR 1045 (28000): Access denied for user 'app_user'#'xxx.xxx.xxx.xxx' (using password: YES)
If it was having trouble finding the new IP, then that command would probably just hang and timeout, so it seems to be an authentication issue. My password is definitely correct, but the application is using the same password as when the app was connecting successfully so it's not an issue of mistyping it.
I've tried deleting the user app_user from the database and re-creating, exactly as I did in the beginning:
CREATE USER 'app_user'#'xxx.xxx.xxx.xxx' IDENTIFIED BY 'mypassword';
GRANT SELECT ON mydb.* TO 'app_user'#'xxx.xxx.xxx.xxx' IDENTIFIED BY 'mypassword' REQUIRE SSL;
FLUSH PRIVILEGES;
I'm not sure if the DB server IP change is just a coincidence, and maybe there's some other issue.
The entry for app_user in select user, host from mysql.user shows the same IP address as in the Access Denied message above. For what it's worth, I tried changing the DB user host to * and got Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server.
Could this have something to do with SSL being required by connection attempts from this user?
The problem was related to the REQUIRE SSL in the privileges for my user. Without it, I could connect just fine. I got things working again by putting my client-cert.pem and client-key.pem files on the application server, updated my.cnf by adding:
ssl-cert = /path/to/client-cert.pem
ssl-key = /path/to/client-key.pem
...under the [client] section and restarted the mysql server.
However, I still don't understand why I was able to connect successfully before when I had done none of these things.