I\'m trying to create model using phalcon. But when I type phalcon model polls
I get an error as ERROR: SQLSTATE[HY000] [1045] Access denied for user \'root\'
I don't think this is a port issue, the request is reaching it's destination. Using root@localhost
will work when logging in through the command line (mysql -u root -p
) but you don't want to use it for connecting with your code. Keep in mind that when establishing your connection, you need to use host=localhost
or host=127.0.0.1
explicitly. If you use the IP address (even on the same server), you will get access denied.
[user@localhost ~]# mysql --host=127.0.0.1 --protocol=TCP -u root -p
Enter password:
mysql>
[user@localhost ~]# mysql --host=192.168.1.10 --protocol=TCP -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'hostname' (using password: YES)
Here are the steps I'd recommend taking:
If source of script is same server as MySQL.
CREATE USER '<user>'@'localhost'
IDENTIFIED BY 'password';
GRANT ALL
ON <database>.*
TO '<user>'@'localhost';
If the connection is always established from the same place but a different location than MySQL, run the following on the command line.
CREATE USER '<user>'@'<IP_address>'
IDENTIFIED BY 'password';
GRANT ALL
ON <database>.*
TO '<user>'@'<IP_address>';
If the source of the connection varies, run the following command.
CREATE USER '<user>'@'<IP_address>'
IDENTIFIED BY 'password';
GRANT ALL
ON <database>.*
TO '<user>'@'%';
Here is a link to the documentation if you have any questions.