Search code examples
mysqllocalhostmamp

Can't connect to mysql db using root@localhost in a mamp environment


I'm working on a MAC in a MAMP environment. so when i try to connect to the database i get this error

$this->db = mysqli_connect('localhost', 'root', '');

I can log in with PhpMyAdmin as the root user.

mysqli_connect(): (28000/1045): Access denied for user 'root'@'localhost' (using password: YES)

my root user is set like this

user: root
machine: localhost
password: no
global rights: ALL PRIVILEGES
grant: yes

Does anyone know how to resolve this problem?


Solution

  • The PHP Manual here says about the password field:

    If not provided or NULL, the MySQL server will attempt to authenticate the user against those user records which have no password only. This allows one username to be used with different permissions (depending on if a password as provided or not).

    So, either do mysqli_connect($host, $user); or mysqli_connect($host, $user, null);