Search code examples
phpmysqlserver

Why can't my server connect MYSQL database when I can access and ssh it?


I'm setting up my server and I can connect to the DB using `mysql -u root -p` and by ssh from outside the server.

But I am getting `SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)` when I start my server.

I have no clue why this is happening. I am able to ssh and connect with the same password without issue. On my server I am using port 3360 and host 127.0.0.1.

I tried reinstalling mysql, changing passwords and using the remote server IP but nothing works. I want my server to have access to the database


Solution

    1. Check Password
    2. Check if the User root is allowed to connect
    3. Check the MySQL server configuration file (usually located at /etc/mysql/my.cnf or /etc/my.cnf) for the bind-address parameter. Make sure it is set to 127.0.0.1 or localhost
    4. Check Firewall Settings on spesifically port 3360
    5. Check Error Log in the MySQL data directory,

    Maybe this helps