Access denied for user root@localhost on Ubuntu and OS X

43
February 12, 2019, at 09:50 AM

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.

READ ALSO
Question marks returned instead of Arabic characters ONLY when xampp servers are launched from within program

Question marks returned instead of Arabic characters ONLY when xampp servers are launched from within program

As the title says, question marks are returned only when I run mysqldexe and httpd

62
MySQL - sub query on the same table [duplicate]

MySQL - sub query on the same table [duplicate]

This question already has an answer here:

44
How to update image in mysql database using angularjs [on hold]

How to update image in mysql database using angularjs [on hold]

I am learning angularjsBut I am fetching some problem in image updating

63
mysqli_error() expects parameter 1 to be mysqli, null given ERROR

mysqli_error() expects parameter 1 to be mysqli, null given ERROR

I'm setting up a new server and having some issues with outdated coding

72